Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Building headers

From: HTML5 First Look

Video: Building headers

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.

Building headers

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.

Show transcript

This video is part of

Image for HTML5 First Look
HTML5 First Look

50 video lessons · 75557 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 3m 56s
    1. Welcome
      1m 1s
    2. Using the exercise files
      1m 50s
    3. Who is this course for?
      1m 5s
  2. 21m 12s
    1. Exploring prior standards
      4m 26s
    2. Why do we need HTML5?
      3m 32s
    3. HTML5 timeline
      4m 24s
    4. Current HTML5 support
      4m 25s
    5. What HTML5 is (and what it isn't)
      4m 25s
  3. 27m 49s
    1. HTML5 vs. HTML4
      3m 25s
    2. New structural tags
      6m 1s
    3. New content tags
      4m 7s
    4. New application-focused tags
      5m 32s
    5. Deprecated elements
      4m 28s
    6. API overview
      4m 16s
  4. 22m 29s
    1. Content models
      5m 33s
    2. Understanding the outline algorithm
      3m 21s
    3. The role of ‹div› tags
      4m 20s
    4. Using ID and class attributes
      2m 6s
    5. DOCTYPE declarations
      4m 16s
    6. Character encoding
      2m 53s
  5. 41m 27s
    1. Basic page structure
      3m 40s
    2. Structuring top-level elements
      7m 30s
    3. Structuring interior content
      8m 42s
    4. Building headers
      9m 11s
    5. Checking document outlines
      5m 46s
    6. Ensuring cross-browser structure
      6m 38s
  6. 27m 53s
    1. New input types
      5m 57s
    2. Setting form autofocus
      2m 53s
    3. Using placeholder data
      4m 4s
    4. Marking required fields
      3m 24s
    5. Working with number inputs
      5m 49s
    6. Using date pickers
      5m 46s
  7. 1h 1m
    1. Canvas overview
      6m 21s
    2. Adding canvas content
      8m 58s
    3. Drawing in the canvas environment
      12m 9s
    4. Drag-and-drop API overview
      6m 18s
    5. Offline applications overview
      7m 11s
    6. Video overview
      5m 45s
    7. Encoding video
      8m 23s
    8. Adding video
      5m 58s
  8. 57m 33s
    1. Geolocation API overview
      5m 50s
    2. Web storage API overview
      5m 40s
    3. WebSockets overview
      4m 16s
    4. CSS3 overview
      6m 38s
    5. Enhancing typography with CSS3
      7m 42s
    6. Using @font-face
      7m 11s
    7. Styling HTML5 with CSS3
      10m 23s
    8. Using CSS3 transitions
      9m 53s
  9. 5m 6s
    1. Final thoughts
      3m 49s
    2. Goodbye
      1m 17s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML5 First Look.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.