HTML Structural Tags



index
Disabled back button Next Section
printable version

Section 1: Overview

While the purpose of HTML is to provide structure to an online document, there are certain tags whose only purpose is to structure page content.

In the pre-HTML5 era the <div> tag was the primary mechanism for creating blocks of content in an HTML document.

HTML5 has added several new more targeted semantic tags that replace the blunt <div> tag.

The <div> tag will still be discussed as it is still useful for grouping tags when the grouping doesn't require semantic meaning.

This section will also discuss additional ways of organizing page content, such as lists and tables.

Section 2: Legacy Grouping Tags

We introduced the legacy grouping tags in the HTML Basics notes.

<div> tag

A <div> tag is used to define a generic container or division within the content of an an HTML document, and the tag itself has no semantic meaning.

<span> tag

The span element is an inline container for pieces of text, used for grouping and applying styles to inline elements.


Well, <div> and <span> tags are great, but <div> tags have limitations. One of those limitations is the common affliction that strikes many web developers known as divitis!

  • Divitis is a chronic syndrome that causes web developers to wrap elements with extra <div> tags associated with IDs such as banner, sidebar, article, and footer for semantic and/or positioning purposes.
  • Divitis is also highly contagious. Developers pass divitis to each other extremely quickly, and since divs are invisible to the naked eye, even mild cases of divitis may go unnoticed for years.
  • Here is an example:

    <div id="navbar_wrapper" >
    <div id="navbar" >
    <ul>
    <li><a href= "/" >Home</a></li>
    <li><a href="/">Home</a></li>
    </ul>
    </div>
    </div>

  • The above example includes an unordered list, which is already a block element, wrapped with two div tags that are also block elements.
    • The id attributes on these wrapper elements tell us what they do, but you can remove at least one of these wrappers to get the same result.
    • Overuse of markup leads to bloat and pages that are difficult to style and maintain.
  • Divitis is so prevalent that you can catch it from many of the free CSS templates at freeCSStemplates.org, like the Orange Mint template. Be sure to download the zip file and look at the HTML code. *shudder*
  • There is hope that HTML5 will lead to a cure for divitis, because the HTML5 specification introduces new tags specifically designed to divide a page into logical regions like sidebars, headers, footers, and sections.
Section 3: New HTML5 Semantic Tags

As noted, the new HTML5 semantic tags include <header>,<hgroup>, <section>, <nav>, <article>, <aside>, and <footer>.

Page sections.

Page Sections Using New Tags

Although the figure above shows each of these tags in specific locations, in reality they don't do anything special until you associate them with a particular style in a CSS sheet.

Section 4: Headers and Footers

<header> tag

This tag is used to define a header for some part of a Web page, be it the entire page, an <article> element, or a <section> element.

A header element is not required.

The header can also contain navigation, or the <nav> tag.

You're not restricted to having just one header on a page.

<hgroup> tag

The purpose of the <hgroup> tag is for grouping titles with their associated subtitles.

In some cases, a page, article, or section may require more than one heading, such as where you have a title and a subtitle.

An <hgroup> tag can only contain a group of <h1>–<h6> tags, and it should be used for subtitles, alternative titles, and tag lines.

Here is an example:

Here's more from the html5 Doctor.

<footer> tag

A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.

You are not restricted to use one footer element per site; you can use multiple footers, each of which will then become the footer for that section of the document.

Read more from the html5 Doctor.

Section 5: Sections, Articles, and Asides

<section> tag

This element represents a section of a document or application, such as a chapter or a section of an article or tutorial.

Although a <section> is the most generic of the sectioning elements, it is a block of related content, whereas a <div> is only a block of content.

Section elements typically have a header, although it is not strictly required.

<article> tag

The <article> tag is used to define an independent item on the page that can be distributed on its own, such as a news item, blog post, or comment.

The <article> element is a specialized kind of <section>; it has a more specific semantic meaning than <section> in that it is an independent, self-contained block of related content.

In addition to its content, an article element typically has a heading (often in a header element), and sometimes a footer.

Choosing between <div>, <section>, and <article>

To decide whether a <div>, <section>, or <article> is appropriate, choose the first suitable option:

  1. Would the content make sense on its own in a feed reader? If so use <article>.
  2. If not, is the content related? If so use <section>.
  3. Finally if there’s no semantic relationship use <div>.

<aside> tag

An <aside> tag represents a section of a page that consists of content that is tangentially related to surrounding content and that could be considered separate from that content.

An aside is a conversational digression, and belongs solely within an article or section tag, not independent of it.

Use an aside to wrap some content that is related to the current article or section, but with information that’s not essential to understand it, like complementary information, trivia, etc.

It is key to note that the definition of <aside> refers to sidebars in printed media, such as a magazine or leaflet.

Here is an example of an aside:

Section 6: <nav> Tag

This is a container for the primary navigation links on a Web page and allows you to group together links, resulting in more semantic markup and extra structure that may help screen readers.

The specs note "Not all groups of links on a page need to be in a nav element – the element is primarily intended for sections that consist of major navigation blocks."

Nav elements may have headings.

Here is some example code:

Section 7: Positioning Reminder

Remember that the semantic tags don't do anything special until you associate them with a particular style in a CSS sheet.

Section 8: Other New Structures

There are additional new "structure" tags that don't fit well in this section, including <details>, <summary>, and <mark>.

Section 9: Let's Play

Click the "Edit and Click Me >>" to see the results of the html code in the left panel in the panel on the right.

Then, play around with the html code, making changes and seeing the effect of those changes in the right panel.

Section 10: Resources