Start learning with our library of video tutorials taught by experts. Get started
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.
Of all of the new HTML5 elements, the section and article elements have gotten an overwhelming amount of attention. This is mainly due to the confusion about when it's appropriate to use one over the other. That's a discussion I want to save for a little bit later on. But right now I want to introduce these elements, starting with the section element. So here we are in the HTML5 author view spec, and we are looking at the section element. Again, we can see, category-wise it belongs to the Flow and Sectioning content-- again, more on those content models coming up in just a little bit.
If I scroll down a little bit, we can get a description of what the section element is. Notice that it represents a generic section of a document or an application. In this context, it's a thematic grouping of content, typically with a heading. So keep that in mind that it is a semantic grouping of content. I'll give you couple of examples, like, for example, it might be a chapter, various tabbed pages in a tabbed-panel dialog box or tabbed page or the numbered sections of a thesis or even say the numbered sections of a specification such as this one. It mentions also that a web site homepage could be split into sections for introduction, news item, and contact information, and again, this kind of hints at the fact that a lot of times these are judgment calls.
So introductory content, for example, does that belong in a section, or does that belong in a header tag? So these are really decisions that you as a web author have to make. The first note that we see right here basically says, "Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the element." This is our first hint of the confusion that is surrounding whether you use a section element or an article element. And to me this is pretty clear. It basically says, okay, if you have a semantic grouping of content and you want to encase it in an element and group it, the first question you're going to ask yourself is, is that content going to be syndicated? Will I reuse it? Will I publish it somewhere else? If the answer to that is yes, then the article element is the one you want to use, and we'll talk more about the article element in just a little bit.
But if not, then the section element is the one you want to use. Further note, another note down here says, it is not a generic container element. So a lot of times people are using the section elements instead of the div tag, but that is not always appropriate. When an element is needed simply for styling purposes or as it mentions here, convenience for scripting, then you are encouraged to use the div element instead, and not a section. Another general rule that it mentions right here in the note is that, "The section element is appropriate only if the element's contents would be listed explicitly in the document's outline," and that's the first mention of a document's outline.
That's generated by HTML5, and that is a subject that we are going to talk a lot about in this title, so sort of file that away. In the next chapter, we are going to get in to document outlining and suctioning content, so this is just sort of setting all of that up if you will. Now if I scroll down a little bit, I can see a couple of examples here, and notice the first example they have. It has an article element with sections inside of it. So you can have, say an article, like a blog post, for example, and that blog post could be split into different sections.
If we scroll down a little bit more though, we can see another example where we simply have a section element all by itself. So you have some graduation ceremonies, and we have different sections in that. You can actually have articles inside of sections, sections inside of articles, sections inside of sections. Keep in mind that it is just a semantic grouping of content. So, all the content has to relate to each other, and in the case of using the section element, it's content that you wouldn't want to repurpose or republish on its own. So, now that we have a better idea of what the section element is, let's go ahead and use it.
So I am back here in my HTML authoring tool, and I have html5.htm open from the 02_05 folder. And if I scroll down a little bit here in my code, I can see right after my nav element, I have a div with an ID of main content. Now, it's always a judgment call. But if you look at the way that the page is structured, we have our main site navigation, main content, and then we have a sidebar directly after that. It really would make sense to go ahead and introduce this content as belonging to each other. Right now, the div is doing that for us, but that's a very generic container.
It's not semantic at all. So I am going to replace the div main content--make sure I go ahead and get everything there--with a section tag, and I am going to do the same thing for the closing tags. Make sure you have the opening and closing tag there, and then again, I am going to go ahead and save that. Again, we face another judgment call directly underneath that; we have another div tag here with an id of sidebar, and we have to decide what type of element that belongs to. Now, I could go ahead and do a section so that we would have multiple sections here, one with the main content and one with sidebar content. But there are actually elements that we haven't talked about yet that are more appropriate, so we'll get in to that in just a moment.
So that's a very brief introduction to the section element. Now you can probably imagine that we have a lot more to discuss involving sections, the article element, and kind of how they are used to structure pages, but before we get in to all of that, I want to first finish introducing the remainder of our new structural tags, and we'll move on to that next with the article tag.
There are currently no FAQs about HTML5: Structure, Syntax, and Semantics.
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.