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.
Now as you can see, you can upload a local HTML file, you can input a valid URL, or you can enter code directly into this sample section. Now, I am going to show you guys the other ways to check the generated outlines of your pages a little bit later on, but for right now, the HTML5 outliner is perfect for what we want to do. Before we do this, I want to make a quick point. This chapter is admittedly going to be a bit of a technical exercise. At the end of it, you might say to yourself, yeah okay, but why do I need to pay so much attention to all this? If you are using proper semantic tags to identify content, and it looks okay in the browser, what's the issue, right? Well, that would be true if just humans read your site.
However, the fact is that automatic outline generation is very important for search engines, assistive technologies, syndication, readers, and other web crawlers. If you have a poorly formed document, your table of contents will be confusing, search engines won't be able to properly rank page data, and navigation through assistive technologies can be hampered. Trust me, it is worth putting in the time to learn this. Now, the first thing I want to do is show you exactly how individual sections are created, so what we are going to do is we're just going to type our HTML directly into the outliner itself.
So the first thing I am going to do is just go ahead and get rid of everything but the doctype and the title. Now, we don't even really need those. It will work with snippets, but it'll give us a nice sort of grounding, a base if you will. So the first thing I am going to do is just type in a section element directly in there, and there is nowhere to save it. I just want to outline it. Now when I do that, it looks like something weird has happened, right? Now the section element is supposed to create a single section in your document, but here we see we have an untitled section in an untitled section.
Now, that seems kind of odd, until you realize that the body tag itself is a sectioning element. So what we are really seeing here is we are seeing the body tag as untitled, and then we are seeing our initial section element as well. All right, let's go back a little bit and let's take advantage of those tags we learned earlier to create four individual sections. So I am going to start with a nav, and then I'll close my nav tag there. Next, I'll do section, close section, and we just had one. Then I'll do article, close article, and then finally, I am going to do an aside here.
Okay. I'll go ahead and outline that, and notice that inside of our body tag, we now have four beautiful untitled sections. Untitled sections can be really, really confusing for table of contents and in generating these outlines, so one of the first things I want to mention here about sectioning content is that when you have a heading inside sectioning content, the initial heading that comes in contact with, the very first one, is used to title the section and not create its own unique section.
So let me go back a little bit, and I am going to modify this. Just in front of my nav element, for example, I am going to add an h1 tag and I am just going to say "Explore California" inside the h1 tag. There we go. And then I am going to go into all my sections and give them headings as well. Inside the nav section, for example, I am going to do an h2 tag. And again, one of the things that is really interesting about this--and this is going to say, "site navigation"--is that the way that we do headings now in HTML5, we have got a lot more latitude.
In the past, you have really only wanted one h1 per page, that sort of thing, and then you used sort of hierarchy of headings as you go down through the page. Now each section has its own sort of internal hierarchy, so I could have very easily use an h1 here, and still been in conformance. Not very many people are adopting that yet, because some of the search engines do penalize for things like that, so it's still evolving, but I just want to let you know that you are able to do that. So again, I will do another h2 inside of my section here. This section is going to say, "Our Tours." I am going to close that.
Let's go down to article again, and inside of article, we'll have another h2 tag. This will say, "Tour Reviews." Close that. And then finally, in our aside here, I am going to do another h2 and I am just going to say, "Monthly Specials." Okay, cool! All right, so now I am going to go ahead and outline that. And now instead of seeing untitled section, now this document is starting to make sense.
So we have Explore California, and inside that we have our Site Navigation, Our Tours, Tour Reviews, and Monthly Specials. And I think you can start to see a reason to embrace this. We are seeing a very clear structure in our document just by using the proper elements in and titling them correctly. I am going to go back, and the last thing I want to do here before we move on to our next exercise, let's talk about nesting elements inside of other elements. So, nesting elements just provides a more complex structure. So, for example, if I were to go into the Our Tours section here--and I am just going to hit Return a few times to create some empty space here--and inside this, for example, maybe I was interested in putting an article in here, so I am just going to do another article tag.
So I am creating a nested article inside of the Our Tours section, and the first thing I am going to do here is do an h2. So I am sort of establishing the hierarchy of the initial header of every section is going to be an h2 and then I would nest from there. So this is going to be Cycle California, and I will close the h2 tag. I'm going to keep the article open for just a moment here. Inside this article, I'm going to nest another section, and in this section, this time since it's nested further, I will use an h3. And here I am going to do Trail Reviews, so maybe there are some trail reviews available for the Cycle California tour.
Okay, at this point, I am going to close the section, and then I am going to go ahead and close the article as well. So let's take a look at what that does for us, as you can see that now we have this nested document outline. Inside Our Tours, we have our first tour, which is Cycle California, and inside that, it contains some trail reviews, and you can see in sort of how it's nested. It's really easy sometimes to forget or mix up which elements actually create sections. For example, the div tag, the div tag is used so frequently to create sections in previous versions of HTML, it seems like a natural choice for creating sections here, except that it doesn't, not in HTML5 anyway.
Let me show you what I mean. I am going to into the code here and inside our Tour Review articles, I am just going to create a new line. And inside that, I am going to go ahead and create a div tag, and we'll just use an h3 since we are nesting inside this article. So we are just going to do an h3 here, and inside this h3, since this is Tour Reviews, why don't we go ahead and review the Backpack California tour? And so then I will close the h3, and then I will close the div tag. Now remember, div tags don't create sections, right? So if I outline this, it sure does look like they create sections because there is a new section right there, Backpack California.
So do div tags create sections or don't they? Well, it's very easy to be confused by this, so let me show you. If we go back into our code and we replace the h3 with a paragraph tag-- so inside the div tag I am going to replace that h3 with a paragraph tag and outline it-- we can see that that now goes away. So we know, in that case, it wasn't the div tag that was creating the section; it was the heading tag, the h3 tag. The div tag is not sectioning content and will not create a new section. It's really easy to get confused about that.
So just remember that as far as headings go, when they are not the first heading element in the section, they are going to create their own implicit section. That, and the fact that the rules for using heading levels have changed a little bit in HTML5, means the headings really deserve their own discussion, and we are going to go ahead and dive into that discussion next.
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.