Moving markup towards HTML5

Hav­ing read John Resig’s “HTML5 Shiv” art­icle and Remy Sharp’s “HTML5 enabling script”, it felt like the right time to begin the full fledged migra­tion from XHTML to a cross browser com­pat­ible HTML5 blog. All in all the pro­cess of updat­ing the tem­plates was pain­less, tak­ing about an hour or so to modify the Word­press Sand­box theme.

To enable IE6 and IE7 sup­port for new HTML5 tags, which are not nat­ur­ally styled, some JavaS­cript is neces­sary. As per the ‘shiv’ art­icle, Remy Sharp has a small script that cre­ates DOM ele­ments, one for each type of new HTML5 tag, the simple act of doing so leads Inter­net Explorer to apply styles to said tags. I slightly mod­i­fied the exist­ing script to add the recently pro­posed hgroup.

(function(){
	if(!/*@cc_on!@*/0) return;
	var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,
		eventsource,figure,footer,hgroup,header,mark,menu,meter,nav,output,
		progress,section,time,video".split(','),i=0,length=e.length;
	while(i<length){
		document.createElement(e[i++])
	}
})();

Even though these tags accept style they don’t come with their default ren­der­ings. For that we need a bit of CSS to make block ele­ments behave as they should.

article, aside, dialog, footer, header, section, footer, nav, figure {
	display: block;
}

I’ve also updated the Eric Meyer reset script, remov­ing now deprec­ated HTML 4 tags and apply­ing reset to the new ele­ments, so they do not unex­pec­tedly inherit pad­ding, mar­gin, etc. in the future. These changes are not yet exhaustive.

Mov­ing onto the page’s actual markup, the new DOCTYPE and char­ac­ter encod­ing set­tings are remark­ably simple. Stand­ards based web devel­op­ment is get­ting easier. For browsers that do not sup­port HTML5, the new DOCTYPE still trig­gers stand­ards mode. The xmlns HTML attrib­ute is no longer neces­sary and the profile attrib­ute has been dropped.

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
	<meta charset="UTF-8" />
	<title>FofR Online</title>

The header sec­tion has been placed in the appro­pri­ate <header> tags, and sim­il­arly with the footer. I’d hoped to include the ‘About Me’ sec­tion within this, but as part of the spe­cific­a­tion you can­not include head­ings within a <footer> element.

Each of the posts comes wrapped in an <article> tag, i.e. an inde­pend­ent ele­ment with con­tent that could stan­dalone. Within are the respect­ive <header> (con­tain­ing title and date) and <footer> (con­tain­ing meta links) ele­ments. Tech­nic­ally the meta links could be marked as <nav>, but the former is more fit­ting and still accept­able use.

The date makes use of HTML5’s <time> ele­ment, with a datetime attrib­ute that gives the pre­cise post­ing time, includ­ing timezone offset.

The pre­vi­ous and next links that fol­low the art­icle can com­fort­ably sit within a <nav> tag. Sim­il­arly, my side­bar region is pre­dom­in­antly nav­ig­a­tion based with lists of archives and cat­egor­ies, it’s been marked as such.

<article id="post-67" class="">
	<header>
		<h2 class="entry-title"><a href="" title="" rel="bookmark">POST TITLE</a></h2>
		<div class="entry-date">
			<time datetime="2009-04-30T15:54:28-07:00" class="published" title="2009-04-30T15:54:28-07:00">April 30, 2009 &#8211; 3:54 pm</time>
		</div>
	</header>
	<div class="entry-content">
		POST
	</div>
	<footer class="entry-meta">
		META LINKS
	</footer>
</article>

<nav id="nav-below" class="navigation clearfix">
	<div class="nav-previous"></div>
	<div class="nav-next"></div>
</nav>

One avenue I should explore is the inclu­sion of the <section> tag, which I’d like to break up indi­vidual posts, prob­ably by split­ting the con­tent at level three head­ings down­wards; thereby becom­ing the header of each new section.

It’ll be a while before the real bene­fits of HTML5 can be fully appre­ci­ated by every­one, but it feels good to make a start, how­ever small that step may be.

4 Comments

  1. Posted June 10, 2009 at 7:19 pm | Permalink

    Great post. I’ve been work­ing on port­ing a site to HTML5 in the past few weeks and have found it a fun chal­lenge. I hadn’t even thought about includ­ing head­ers and foot­ers within other ele­ments. Seems like an inter­est­ing approach, where it makes sense.

  2. Ms2ger
    Posted June 11, 2009 at 1:40 am | Permalink

    You might want to note that the cor­rect syn­tax for the doc­type doesn’t include a ‘“‘. The one you have now actu­ally trig­gers quirks mode in at least Fire­fox and Opera.

  3. Posted June 11, 2009 at 3:35 am | Permalink

    Good spot, fixed.

  4. Posted June 28, 2009 at 11:30 am | Permalink

    Good art­icle. You got me star­ted on HTML 5 con­ver­sion of my theme. It took me a while to do it. The base struc­ture is sim­ilar to yours. The sad part is that while the HTML val­id­ates 100%, to make it work in all browsers I still need to use a lot of IE6 hacks, and this turns into invalid CSS. Any­way, if you are inter­ested here is my Word­press HTML 5 exper­i­ence: adopt­ing my blog to 5 part 2 the structure

Post a Comment

Your email is never shared. Required fields are marked *

*
*