Viewers: in countries Watching now:
Gain a deeper understanding of HTML5 and learn how to create richer, more meaningful web pages with structural tags and descriptive attributes. In this course, author James Williamson presents an overview of HTML5 and its development, defines the new tags and attributes, and discusses how browsers parse and display HTML5 content. The course also includes step-by-step instructions for constructing an HTML5 document with a header and footer, navigation, content groups, and formatting.
If you're making the jump to HTML5 from XHTML, you've probably heard some of the concerns over the syntax changes. If you haven't, most of it centers on the rather loose coding standards of HTML compared to that of XHTML. Now rather than go over them one by one, let's just re-examine our XHTML document and discuss some of the syntax rules that governed writing XTML. So we're looking currently at the xhtml.htm file that's found in 02_02 directory, and I just want to point out some of the coding rules that we pretty much had to follow when we were writing XHTML.
For one thing, notice that all of the tag names are lowercase. Notice that for any tags that had attributes, those attributes are in quotation marks, and we have some tags that don't ever contain content, so those tags are being self-closed. You can see the meta tags here are self-closing. If I scroll down a little bit, I have a couple of line break tags down here, and those guys are self-closing as well. Now, those rules were driven, for the most part, by XML syntax requirements. Because most pages were served as text/html rather than application/xhtml, these syntax rules went largely ignored by browsers if authors didn't follow them.
Now, I am going to switch over to html5.htm. Again, this is from the 02_02 directory. It's the exact same file that we created in the last movie; it just has the content actually dumped into it. I want to examine some of the syntax rules now for HTML5. It's very loose, especially when you compare it with XHTML. Now, I am going to do some changes to the document here. If you're following along with me, you don't necessarily have to do these changes because when I am done with all of them, I am going to revert back to this file. So if you just want to kind of hang out for second and watch what I am about to do, that's fine. If you want to do it with me, that's cool too.
So let's go to the head tag here. Maybe I might take a look at this thing and make it all caps. So, I'll make it all caps, and I'll go to the title tag here and make the title tag all caps in the opening tag, but not in the closing tag. Quotation marks around utf-8. Let's go ahead and get rid of that, so no quotation marks around that. And just to really throw things, I am going to go to the body tag and I'll capitalize just the O in body. So, it kind of looks kind of cool, right? Believe it or not, this is all conforming HTML.
You can even take this further. In the HTML spec, for example, some of the opening and closing tags are optional. In terms of being optional for both the opening and the closing tag, you have HTML head and body. That means that I don't need the HTML opening tag, I don't need the head tag, I don't need the closing head tag, I don't need the opening body tag, and I don't need either of these closing tags. Some tags are just entirely optional to close. For example, list items, definition lists, paragraphs, table rows, table headings, table data cells, those types of things, we don't necessarily have to close them.
So I can come up to a paragraph here, for example, and just go ahead and get rid of the closing paragraph tag, and I am just going to go ahead and save that, okay? So, this is probably making some of you break out in cold sweats. Just to prove to you that this is conforming HTML, I am going to go ahead and validate this. Now, I know at the beginning of the title, I said, "Hey! I am not going to do anything in Dreamweaver that you can't do in other authoring programs," but I'm going to save myself a little bit of time here. Dreamweaver does have W3C validation baked right into it in the Dreamweaver CS5 version, which is really nice, handy tool.
Now if you don't have that, that's fine. You can go out online and you can got to validator.w3.org, and this is W3C's markup validation service. This is the same one that Dreamweaver uses. And you can either validate by a valid URL, you can upload a file, or you can just copy and paste your HTML directly into that. So if you do want to do this along with me, feel free to use this service instead of the Dreamweaver service; it's the exact same thing. So back in Dreamweaver, I am just going to go ahead and validate this document. And you can see, it says, hey, no errors or warnings found; everything is fine.
I am not even going to pretend that this is good authoring practice. I am just telling you this is allowed within the HTML syntax. For those of us that are used to writing using all those XHTML rules--and I have had them hammered into me year after year-- it can be a bit jarring. To help you understand this a little better remember, HTML5 and HTML itself is just a markup language; it's not an authoring language. It's designed to simply identify content, and that's it. The web is kind of a messy place, and the role of most user agents is to display the content the way the author intended, even if they're messy, non-human authors.
Now, because of this, HTML syntax gives us kind of a wide amount of latitude to how that content is formed. Now that we know kind of how far we can take it, let's take a look at what's practical within the scope of good authoring practice. So, the first thing I am going to do is I am going to come in here and sort of undo all those changes that I--those horrible, terrible changes that I made to the document. I am going to go ahead and undo those, okay. There we are. Good! So I am kind of back to where I started from. One of the things that I am going to do is I am going to keep all my tags in lowercase. Now, you could do one or the other, but I'd really recommend being consistent with it.
So I'm just going to go ahead and keep mine in all lowercase. I am also, going to keep the quotation marks around the attribute values. In some cases, you can pass multiple values as an attribute, and if you were to do that, you would definitely need the quotation marks. So, if you pass in another form of encoding along with this, you would need the separation. You would need the quotation mark. So just as a general rule, I err on the side of caution and go ahead and add them. Some attributes also contain Boolean values. So, some of the new HTML5 attributes have Boolean values.
Let me show you what I am mean. I am going to scroll down, and you see I've got a div with an id of sidebar, and it has the new hidden attribute. So notice hidden=hidden, so it's kind of redundant. So really, you can just present that this way. You can take off the attribute entirely. Just the presence of the attribute confirms that the value is true for that. So in cases of that syntax, I'm probably not going to put an attribute on there. I am just going to pass the attribute and let the browser go ahead and validate that. I am also going to go up to my link tag that's linking to my external style sheet, and one of the things that we don't need to pass along anymore is the type attribute, so where it says text/css.
Other tags in HTML are considered void--that is, they can never ever contain any content. Like the meta tag, for example. Now, in XHTML, you remember, we had those self-closing tags that I just talked about a moment ago. So, I was trying to bridge the gap between the XML requiring a closing tag and HTML saying, yeah, but there is never anything in it. So these self-closing tags really aren't necessary anymore. And again, the irony involved in these is that everybody that was doing these-- and I certainly was chief among them-- when we were serving our pages as text/html, this was simply badly formed HTML, and it was HTML's loose syntax rules-- the one that I was complaining about--that allowed it in the first place, so...irony.
So I am going to remove that from the link tag. I don't have it on the meta tag, and then I am going to remove it from my line breaks down here as well. And this has probably been the hardest thing for me to break out in terms of a habit. I'm just got so in the habit of self- closing those tags that I don't even think about it when I type them now. So this is something I am still having to sort of break myself from, that we really don't need the self-closing tags. And again, if I want to be consistent with the syntax of HTML, I'll just go ahead and get rid of those. What it really boils down to is that we have more options than HTML5, in terms of how we write our code, not less.
Unfortunately, it also let's people write some really ugly code and get away with it. So my advice is to go ahead and come up with a consistent coding standard that not only conforms to HTML, but that's readable and maintainable not only by yourself, but other authors as well. I'll use my own standard throughout this course, and I have just pretty much described it to you--and if it works well for you, feel free to go ahead and adopt it. Now, for the most part, it's almost exactly like what I was doing when I was writing XHTML. I used all lowercase for the tags. I enclosed my attributes in quotation marks.
I don't self-close those tags any more, however. I also don't serve attributes that are no longer required, like the MIME types, and I don't include attribute values for those global attributes that have a single or a Boolean value. Now, it works for me. It helps me create consistent code and more importantly, it works in all conforming user agents, and it's also backwards compatible, which is a good thing. Now I recommend using the exact same criteria when determining your own syntax standards, and that's actually something that, if you're new to this, I would encourage you to do over the course of the title.
There are currently no FAQs about HTML5: Structure, Syntax, and Semantics (2011).
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.