Feature
Post

Category
Code


Getting Started With HTML5: Part 3

Most of HTML5 seems to be pretty self-explanatory. Unfortunately there are a few things that just aren’t. For example, the complex outlining algorithm, and the section element. It’s confusing as hell and everyone has a their own way. So we may as well dive in head first…

Here’s our working HTML one more time in case you missed it:


<!DOCTYPE html>
<html>
    <head>
    	<title>HTML 5 Demo</title>
	<script>
		document.createElement('header');
		document.createElement('nav');
		document.createElement('section');
		document.createElement('article');
		document.createElement('aside');
		document.createElement('footer');
	</script>
	<style>		
		header,nav,section,article,aside,footer {display:block;border:1px solid #bbb;padding:1em;}

		header,nav,section,article,aside,footer {border:1px solid #bbb;padding:1em;}
		header{background-color:#EFFBFF;}
		h1,h2,nav li {font-family:helvetica,arial,sans-serif;}
		nav{margin:1.5em 0;}
		nav li {display: inline;list-style-type: none;padding-right:1em;}
		article,aside{float:left;margin-bottom:1.5em;}
		article {width:60%;}
		aside {width:28%;margin-left:1em;}
		footer {clear:both;}
		.identifier {background-color:#FFF79F;font-style:italic;}
	</style>
    </head>
    <body>
        <header>
		<p class="identifier">header</p>
            	<h1>HTML 5 Demo</h1>
        </header>
        <nav>
		<p class="identifier">nav</p>
		<ul>
			<li>Home</li>
			<li>About</li>
			<li>Contact</li>
		</ul>
        </nav>        
	<article>
		<p class="identifier">article</p>
		<h2>Terminology and Usage</h2>
		<section>
			<p class="identifier">section</p>
			<ul>
				<li>The header element represents a group of introductory or navigational aids.</li>
				<li>The nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links.</li>
				<li>An article element is "independent" in the sense that its contents could stand alone, for example in syndication.</li>
				<li>The section element represents a generic document or application section...[it] is not a generic container element.</li>
				<li>The aside element represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content.</li>
				<li>The footer element represents a footer for its nearest ancestor sectioning content. </li>
			</ul>
		</section>
	</article>
	<aside>
		<p class="identifier">aside</p>
		<h2>Attribution</h2>
		<section>	
			<p class="identifier">section</p>		
			<p>The main article on this page is comprised of excerpts from the HTML 5 draft.</p>
		</section>
	</aside>
        <footer>
		<p class="identifier">footer</p>
		<p>By Dustin Boston</p>
        </footer>
    </body>
</html>

section

The section element is defined by the W3C as “a generic document or application section…[it] is not a generic container element.” I don’t think one could be any more vague and contradictory. The only saving grace is a couple examples they give, namely tabbed elements, and chapters.

In my opinion this doesn’t necessarily limit you to sticking a section element inside of an article element, or visa versa. It doesn’t have to stand alone, it just has to group elements logically (unlike a div). So while some examples put sections around sets of articles, others put them within, to denote separate portions of the same article.

Our example HTML would be better served to have another section element after the first. That would be a great place to make a snarky comment about the vague and abstract language that only the Consortium can understand.

aside

Fortunately the aside element isn’t nearly as confusing as the section element. Use it as a sidebar with meta information related to the content. Pretty straightforward. You could put quotes, navigation, resources, links etc. inside this little fella. Just keep it related. This isn’t the place for global navigation elements.

footer

The last element in the series is the footer. While typically the last item on a page, a footer could also be used in a section or article. A great example would be all that meta information at the end of a blog post, e.g. categories, dates, tags, etc.

Conclusion

It’s your turn. Mock up your next site in HTML5 and see what happens. It might break, it might not, who knows. The spec is still unstable, but it is starting to gain traction. But definitely try it out. If we all start using it maybe we can have a usable spec in less than 20 years!