Video: Building headersOur page structure is almost finished. I said almost because with the exception of the top section itself, we haven't defined any headings or headers in our document. It may seem that leaving headers until last is a little odd and to be honest I will give you that. I wouldn't normally leave them until the end, but it's really hard to describe why we're going to be defining our headers the way we are without being able to see the rest of the structure. So just this once we will be defining our headers last instead of how I do it normally, which is as I build the page.
Viewers: in countries Watching now:
In HTML5 First Look, author James Williamson introduces the newest HTML specification, providing a high-level overview of HTML5 in its current state, how it differs from HTML 4, the current level of support in various browsers and mobile devices, and how the specification might evolve in the future. Exercise files accompany the course.
- Understanding the history of HTML5
- Using new tags
- Understanding HTML5 semantics
- Coding ID and class attributes in HTML5
- Structuring documents
- Building forms
- Exploring HTML5 native APIs
- Encoding and adding HTML5 video
- Exploring associated technologies such as CSS3
Our page structure is almost finished. I said almost because with the exception of the top section itself, we haven't defined any headings or headers in our document. It may seem that leaving headers until last is a little odd and to be honest I will give you that. I wouldn't normally leave them until the end, but it's really hard to describe why we're going to be defining our headers the way we are without being able to see the rest of the structure. So just this once we will be defining our headers last instead of how I do it normally, which is as I build the page.
So we will go ahead and start at the top, and again at the top we have a nice header tag at the top of our page. We have just inside of that an h1 tag that says Explore California Trail Guide. So because of the way the outline algorithm works in HTML5, it's going to go ahead and take the first heading it comes to, in this case the h1 tag within a section, and use it as the title of that section. Remember, a header tag is not sectioning content. So this h1 is not the title of the header tag. Instead it's the title of the body tag.
That is the first tag up the list that is an actual sectioning tag. It's the sectioning root. So essentially, by placing this h1 tag where we placed it, we are making Explorer California Trail Guide be the title of the page. Now, please don't confuse that with the actual title tag itself. It's not a way to replace that, but if we're creating an outline, that's going to be the first thing in the outline is the body tag element. Now, headings are really important, because if I didn't have that there, this node would show up in the outline as untitled section.
So by having the heading there, that's really good. However, the heading 2 underneath it could cause us a bit of a problem. You see, the first heading in any section is taken as the title of that section. However, each subsequent heading creates its own section. So essentially, if we left this the way it was directly after the body tag section, we would have another section that's titled "your complete biking trail source." That is not what we need. In fact, those two headlines are related.
Explore California Trail Guide and your complete biking trail source are two related headlines, the h2 being the tagline. Well thankfully, HTML5 gives us a way of dealing with this structurally. What I am going to do is go ahead and highlight both of these guys and I am going to wrap them in an hgroup tag. So we are going to use hgroup here. So what the hgroup tag does is it surrounds these headlines or heading content, and it makes all of those headlines relate to each other without creating new sections.
So this way we are essentially telling any user agent parsing this outline that this heading1 tag and this h2 tag belong together and shouldn't be the start of separate sections. Now, with the idea of that whole untitled section thing in mind, if I go down to the nav tag, I can see that this doesn't really have a heading at all. It has a nav tag with an id of mainNav, but if I looked at this in any type of a document outline, it would essentially say "untitled section" and it would might even say that it's a navigation but it would be untitled.
So what I am going to do is something that you probably wouldn't normally do in your own code. Directly after the nav tag, I am going to create a brand-new h1 tag and inside that h1 tag, I am going to type in "Main page navigation" and then I am going to close the heading tag. Now, I am going to hide that through the use of CSS. So when we preview it in our browser, we won't see it. So that is one thing you can do. But in our outline now, when it comes to the navigation, it will literally say "Main page navigation" because we went ahead and added the headline.
Now, one thing that might get a few of you guys a little nervous is the fact that I used h1 tag here and then I immediately used another h1 tag. I have heard dozens of people that are search engine optimization experts tell you only use one h1 tag per page. Well, that was the old way of doing it but guess what? Times are changing. Search algorithms are going to change as well. In HTML5, the h1 tag is a very important tag. It still represents that top-level heading. However, since every single section has its own interior outline, it is quite correct to use an h1 tag as the main heading for that section.
Now, that's going to take a little while to get used to, but trust me, it is the proper way of doing that. Okay, now I am going to scroll down to our Trail Info section right down here and notice that we have a sort of a parent tag, which is the section tag. Inside that, we have an article that has its own heading already built into it. So notice we're using an h1 right there from Northridge Loop. Now, that doesn't look so strange, does it? So now we have a heading 1 that's basically giving us the title of this particular article. It also means that this heading, Ojai Trails, becomes the title for this particular section.
in this case, the trailInfo section. However, again we have two elements right here, the paragraph and the heading 1, that really sort of belong together. This is the sub-navigation for that section and then this is the title and the heading for that section. So you could kind of consider both of those to be in the header of the trailInfo section, and that's exactly what I am going to do. I am going to go ahead and wrap those guys in a header tag. So I am going to add an opening header tag before the paragraph and then directly after the h1 tag, I am going to close that.
So that is a little bit more semantically proper. Essentially, we are just saying that, hey, this content in the section forms the header of the content. So you can have more than one header per page and in fact each section, if it warranted it, could have its own header. We don't need to worry about using any type of an hgroup tag or any other structuring there. All that's working just fine. So again inside the article, the first heading is going to go ahead and identify this content. So it will be used for the title of the article, and if I go down a little bit further, I can see that I have a heading 2 here and a heading 2 here.
so Skill level and Surface. So instead of being used as titles, those are essentially creating new sections within the article. So Skill level is going to be its own section. Surface is going to be its own section. They share the same level of importance because they're h2 tags. If I wanted to nest them, I could make the second one an h3 if I wanted to do that. So there is a reason why we chose an h2 tag here and not an h1 tag. We've already used an h1 tag once within this content. So we want to go ahead and make sure that we are structuring things properly in regards to the type of heading tags that we are using.
Now, I am going to keep scrolling down and I am going to take a closer look at the content inside the aside tag. So first off, we have an h1 tag that's serving as the title of our aside tag. It's working just fine, and inside that we have another section whose class is news and we have an h2 tag inside of that. Now here, we are structuring our headings based on their level of importance inside the section. If we wanted to, we could have made that another h1 tag and that would have been okay. But here we are using an h2 tag.
So really, it's almost always a judgment call as to what the top heading tag inside your section is going to be. That could be an h1 tag, and it would be just fine. In this case, we are using an h2 tag. Now, if I scrolled down into our article, I can see that we have again a heading 1 tag that's serving as a top-level header, then we have an h2 tag that's identifying the individual trail, then we have the h3 tag that's identifying the author, and then finally we have a paragraph that holds the publishing date. Only after all that content do we have the actual review itself.
So if you think about it, all of that content could logically fit inside of a header tag. So I am going to go ahead and highlight that. Then I am going to wrap all that inside of a header tag, just so that we are identifying that as being the header of that particular article. Now, in a lot of cases, we would be done here, but in this case I want to take a closer look at what we have going on inside the header itself. You can see we have an h1 tag that's going to identify or become the title of this particular sectional item, but then we have an h2 tag and an h3 tag.
So these are subheadings or taglines. In this case, it's the subheading of the actual trail and the author's name itself. Well, those we want to go ahead and group within an hgroup tag. Again, we are doing that, and I am just going to go ahead and highlight those guys and group them in an hgroup tag. Again, the reason that we are doing that is we want to make sure that any type of user agent parsing this understands that these headlines are all related and they should not be separate sections. So we are sort of preventing them from forming separate sections. Perfect! So our page is now constructed using semantic structured HTML file markup.
We know the outline we were shooting for and the code structure we created should do it, but how can we be sure? But in our next movie, I am going to show you how to check your document outline to make sure you've structured your page correctly.
There are currently no FAQs about HTML5 First Look.