Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
It's time to finish our page's main header section by adding our page navigation. Now, we already have the nav element, so all we really need to do is go in and add our sites menu. Now, for the most part, how we code menus or related links really hasn't changed at all. So, if you're familiar with the process in HTML 4, you are going to be comfortable with it here. So, we are going to be working in the trails.htm file, and this one can be found in 04_08 folder. Now, one of the things that I want to point out from earlier when we looked at our navigation, if you remember when we looked at the document outline, it basically said NAV Untitled section, or Untitled NAV.
So, we want to correct that. So, one of the first things I am going to do is we will go into the nav element which is found right here in the header. And I am just going to hit Return so that I have got some vertical lines to work with here. And the first thing I am going to do inside my nav element is I am going to identify the section with a heading. So I am going to do an h2, and I am just going to say 'Main page navigation'. Now, obviously that's not something I want to show up in my final document. I don't want that up on the screen, so I am going to use CSS to hide this. So, all this is really doing for us, structurally, is identifying, or giving a title, if you will, to this particular section.
Now, I am going to talk more about the need for this particular heading. So, just as we have done in the past, I am going to go ahead and create an unordered list to group all of our links. That's quite common practice. I am sure it's probably something that you may have done before. Inside the unordered list, I am going to do our first list item, and inside that, I will do our first link. So, we will do an anchor tag, and we will do an href attribute, and this is going to go to the external Explore California site. So, the way that this site is working, the Trail Guide is sort of a sister site, if you will, a brand site to sub-brand of Explore California.
So, we are going to go to explorecalifornia.org, and we are going to go ahead and give that a title, and our title is going to be Visit Explore California. All right, excellent! Now, inside this, the link text is just going to say, 'explore california'. So, that's actually going to the link. I am going to do it in all lowercase, just like cool kids do. I am going to close my link, close my list item, and there is our first menu item. Now, what I am going to do at this point is I am just going to copy this, and then each time I needed a new link, I am just going to paste it and change the relevant data. I like to type as little as possible.
All right, so on the next line, I am going to change the link from explorecalifornia to a document-relative link. In this case, it's going to be trails.htm, and of course, that's the page that we are on, right? And the title of this one is going to be Trail Reviews, and that is also going to be the text for the link, so it will say trail reviews as well. And one of the things I want to do here is I am going to put a class here. So, we are going to use our first class in the structure of a page. I am going to assign that a class of current to let people know it's the current page that we are on, and also stylistically, it's going to change how the link looks on our page.
Okay, so I am going to go down to our next link. I am going to paste that there, and the address for our next link is going to be news.htm. The title will be Trail News and that is also going to be the link text, trail news. We have just got a couple more links to do. The next link is going to be to resources.htm, and the title for that is going to be Trail Resources, and the link will also say resources. Very cool! One more link left to do, and this one is also going to go outside to the Explore California site.
It's going to go to a specific page, in this case tours.htm, and the title for that will be Biking Tours. And we will just go ahead and change the link text to tours, and then I am going to go ahead and save that. So, what I am going to do now is I am going to preview this in a browser, and I want to check the document outline. I want to see if our heading is actually giving the section now a title. So, I am previewing it in the browser, and I am just going to go up and check the outline. And again, Main page navigation is now listed right there in the outline, which is perfect.
That's exactly what we want. Now, I want to go back into the page structure for just a moment and talk about this. For the most part, everything in HTML5 works fantastic, but there are certain things that I kind of wish would change. This is one of them. So if you have a new section of content and that section is started by any of the sectioning elements--nav, article, aside, section-- you have to have a heading at the top of it if you want that section to be titled. Now, in this case, we are forced to put an h2 or some type of a heading inside a nav element that really doesn't need it.
So, we are not going to display that visually. We are going to have to use CSS to hide that so that adds this little burden when we go and style this. But in order for this to be machine readable or to have an assisted device like a screen reader come in say, okay, this is a nav, main page navigation, I need to have this setting in here. I kind of wish that you could identify a section by the ID attribute or maybe a title attribute, but that is not the way that spec works. It's not how the outline algorithm works. So, we are forced to put this content in. It's not non-semantic. I mean, it makes sense, but again, it's a little bit of overkill.
Now, in my mind, it doesn't necessarily have to be there. Now, I also want to point out that nav elements can contain more than just links. You can put whatever structure you want inside of a nav element. So, in this case, we have an unordered list and a heading 2, but you could have paragraphs; you could have really whatever structure you need. But I tend to take the philosophy that you really ought to have as little as possible inside a nav element. It's whatever you need to represent that particular grouping of links and really nothing else. Now, remember the definition for your nav element. It really needs to be a main piece of either site navigation or page navigation, and it's something that you want exposed in the outline, something that you want accessible to assistive devices or other machine-readable devices that are going to come in and look at your code.
So, in this case, our navigation is finished. It's ready to go. We wrapped our main navigation in the header, so we located it in the header, and doing that allows us to establish a structure that's going to work across our entire site. Now, it's worth mentioning here that even though no other link grouping on our page met the criteria for a nav element, it's really quite common of the page structures. Keep in mind that things like blog posts, while blogs typically have a blog roll contained in the sidebar in a list of archived or categorized posts, that would be perfect for nav element. Now, other sites might have secondary site navigation that would be suitable for nav element.
As always, it's really is a judgment call. Now, speaking of judgment calls, remember that while the HTML5 spec points out that links contained in the footer don't often require a nav-- in the spec, it just basically says hey, if there is a grouping of navigation links in the footer, usually the footer is sufficient for that-- you don't need a nav element. But I am going to advice you a little bit differently on that. I want you to consider strongly whether those links meet the criteria for either being exposed in the outline, meaning you want them show up, or more importantly to me, exposed to assistive technology such as screen readers and things like that.
If the answer for any of those links that you might find in your footer is yes, then I really recommend using a nav in those instances, regardless of what the spec actually recommends.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99373 Viewers
56 Video lessons · 112631 Viewers
71 Video lessons · 81455 Viewers
131 Video lessons · 39104 Viewers
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.