Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
This course is designed to quickly lead you through the steps of building an HTML website, from creating a new page to building links and tables. Author James Williamson simplifies the coding process, with straightforward steps you can recreate on your own. The course explains the basic structure of an HTML document, shows how to add text and images, and introduces font styling with CSS. James also offers a bonus design challenge at the end of each chapter, where he asks you to think of a solution before offering his own.
In this exercise I'm going to introduce what's known as inline styles. You see, inline styles are heavily frowned upon in web design, to the point where most designers would describe them with only three words: don't use them. In the end I think it's important for you to know about them, why they're frowned upon, and the rare instances when they are appropriate to use. So I have the inline.htm file opened from the 06_02. Now, what's an inline style? Well, an inline style is a style that's applied using the style attribute. So, we've been using attributes on html tags for quite some time now.
One of the attributes that you can use is the style attribute, and that will control the formatting and the styling for that specific element. To demonstrate that, we've got two headings on the page here. One says "Using inline styles," and the other one is just begging to be styled: "Style me using the 'style' attribute." Well, if you say so. I'm going to go ahead and open up a little bit of space in the opening h2 tag there, and then I'm going to use the style attribute, so style=. In quotation marks, remember what we said about CSS how you know the syntax really has three parts, the selector, and then the properties and the values.
Well, you don't need the selector when you use inline styles because you're targeting only this little guy right here. So now what I need to pass in are properties and values. The first property I'm going to do is color, and color is just that, the word color. That's all you need to do. When you type in a property and you're about to set a value, when we've been using attributes we set values by using a little equals symbol, so you know style=. But in CSS properties and values are separated by using the colon. So I'm going to type in a there. And then I could go ahead and if I wanted to, I could use any manner of definition of color, and CSS allows us to do a lot of different definitions.
We can do hue, saturation, and brightness. We can do RGB. We can use hexadecimal values, which we'll take a look at a little bit later on. Or we can use keywords, and keywords are probably the easiest way to define color, so I'm just going to type in red. Now, after that I'm going to type in a semicolon. The same way that a colon separates a property and a value, a semicolon tells the browser okay, this particular property is finished. We'll move on to the next one. Then I'm going to go ahead and close my quotation marks right there. I'm going to save the file, and I'm going to preview this in a browser.
There you go. And you probably saying to yourself "now, wait a minute. That doesn't seem so bad. Why do you dislike inline style so much?" Well, when you only have two elements on a page, it's not a big deal. Imagine you have a 500-page site, and imagine that you're going to style every single element in your site with inline styles. So you have to go to every tag, write the style attribute, pass the styling in there, and then save it. And then somebody will come back to you later on and say "ooh, all those paragraphs are green, and I need them to all be blue" and now you have to open up 500 pages and edit 500 pages worth of paragraphs and change them.
So yes, efficient, they are not. The other reason not to use them is that they pretty much overwrite any other styling that you do. So if you happen to have one on a page somewhere and forget about it, you could be writing external styles all day long and you're going to be wondering why you can't change the color of this header, and it's because it has this inline style on it. You're not limited to one property. You can put more than one property in here, and to do that you simply just keep going. So right after the semicolon for red, I could say something like font-weight. font-weight controls the thickness of the font, and here I'm just going to say normal.
So instead of bold, I'm going to say normal. And don't forget your semicolon. Font-weight and then a colon normal. So now if I save this and then test it, you'll see that now instead of being bold, which is the default styling for headings, it's now normal. I've given you plenty of reasons not to use inline styles, but how about a reason when you should? There are going to be times when you're passing a file to, like, a really, really old user agent. The user agents that were around before CSS became really standard operating procedure had limited support for CSS and limited support for external styles and inline styles and things like that.
Now you're not frequently going to run into these types of user agents unless you're sending a lot of HTML email, and that is about the only time where it's still cool, if you're will, to use inline style. So if you're going to send out a bunch of emails that are HTML to various parties and you don't really know which email class they're going to be read on, inline styles work pretty much across the board, for the most part. You won't find yourself often needing to use inline styles, but it is helpful to know that they're available if you need them.
There are currently no FAQs about Up and Running with HTML.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.