Updated 22/01/2014 by Dr. Steve
We doctors are a bunch of chums using HTML5 and writing about how we do it. Apart from spurious requests for medical advice, the questions we receive most are about using the
section element, and we realise that we’ve been using the
section element incorrectly all this time.
What we’ve been doing wrong is using
section to wrap content in order to style it, or to demarcate the main content area from the
footer etc. These are jobs for
The section spec says
The section element represents a generic document or application section…The
sectionelement is not a generic container element. When an element is needed only for styling purposes or as a convenience for scripting, authors are encouraged to use the
divelement instead. A general rule is that the
sectionelement is appropriate only if the element’s contents would be listed explicitly in the document’s outline.
section is a blob of content that you could store as an individual record in a database. It generally looks like this (and note that the heading goes inside the section element, not immediately before it):
<body> ... <section> <h2>level of heading = section nesting level</h2> rest of the content </section> ... </body>
With very few exceptions, section should not be used if there is no natural heading for it.
The spec says
The theme of each
sectionshould be identified, typically by including a heading (
h6element) as a child of the
Check your work in the HTML 5 outliner tool. If you see any instances of “untitled section” that corresponds to a section, you’re probably doing it wrong. (It’s fine for a nav or aside element to be untitled, however).
Section is also the most generic of the sectioning elements. Make certain that you don’t really need an
article, which is defined as
a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
What about main content?
Rules of thumb for using
Of course, there are always exceptions, but these should give useful guidance for 99% of cases:
- Don’t use it just as hook for styling or scripting; that’s a
- Don’t use it if article, aside or nav is more appropriate
- Don’t use it unless there is naturally a heading at the start of the section
- The revised spec (as of ) 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.
As blogposts and comments are often syndicated (by being pulled into other blogs or being linked via twitter, reddit etc) they should be articles.
Thanks to Opera’s Lachlan Hunt for fact-checking this article.
Please also note that we haven’t yet changed the WordPress theme to get rid of extra sections, so for now please do as we say and not as we do!