HTML 5 may be the latest and greatest technology, but some browsers don’t have native support for the new semantic elements. Let’s momentarily forget about the really sexy functionality, like full control over the <video> element, and just focus on getting the elements rendered.
The problematic A-grade browsers include IE 8 and below, Firefox 2, and Camino 1 (these last two browsers both use the Gecko rendering engine, which is why they’re both affected).
Let’s start with Internet Explorer.
IE doesn’t believe in HTML 5 elements
Quite simply, IE doesn’t even see HTML 5 elements, much less style them.
This is actually the same issue that we had before HTML 5, where the <abbr> element couldn’t be styled in IE 6, resulting in all manner of workarounds. (Let me add that we’ll also fix the <abbr> element while we convince IE to recognise HTML 5 elements).
The fix
There is hope! The trick, discovered by Sjoerd Visscher, is simply to create the new element using JavaScript, and voilà, IE is able to style it:
document.createElement('header');
John Resig has also written about this HTML 5 shiv.
For example, say you wanted to style the <time> element in italics:
<!DOCTYPE html>
<html>
<head>
<title>Header test</title>
<style>
time { font-style: italic; }
</style>
</head>
<body>
<time datetime="2009-09-13">my birthday</time>
</body>
</html>
This screenshot shows the rendering in IE before we apply the fix:

To apply the fix, add the indicated line of code:
<!DOCTYPE html>
<html>
<head>
<title>Header test</title>
<style>
time { font-style: italic; }
</style>
<!-- Add this line -->
<script>document.createElement('time');</script>
</head>
<body>
<time datetime="2009-09-13">my birthday</time>
</body>
</html>
Now after we’ve applied the fix, it’s correctly styled in IE:

One hit solution
For everyone’s convenience, I wrote a single JavaScript file that can be included to create all the HTML 5 elements (and the <abbr> element) for IE.
Download the IE HTML 5 enabling script
Include the script in your <head> tag, and you’ll be able to style the elements appropriately in IE:
<!--[if lte IE 8]>
<script src="html5.js" type="text/javascript"></script>
<![endif]-->
Note that I’ve used a conditional comment to only apply this to IE 8 and below. It’s my hope that IE 9 and onwards will support HTML 5 elements, but when that day comes, make sure to double check the conditional!
Conditions & Gotchas
There are a couple of things to be aware of when using the HTML 5 shiv.
JavaScript required
This obviously means that your design now depends on JavaScript. Personally, I feel that if you’ve used semantic markup for your site and the elements can’t be styled, the content is still completely readable.
Here’s a screenshot of the Full Frontal web site, written using HTML 5 elements, rendered in IE with and without JavaScript enabled:

You can see in the second screenshot that the content isn’t perfect, but it’s still readable — it cascades down correctly, much as if CSS were disabled.
A little head is always good
If you create the new element and don’t use a <body> tag (which is perfectly valid HTML 5), IE will put all those created elements inside the <head> tag. Pretty crazy, but you can easily avoid this by always using both the <head> and <body> tags in your markup. Leif Halvard explains further with demos.
Firefox 2 and Camino 1 rendering bug
Both Firefox 2 and Camino 1 have a bug in the Gecko rendering engine (specifically versions prior to 1.9b5):
Firefox 2 (or any other Gecko-based browser with a Gecko version pre 1.9b5) has a parsing bug where it will close an unknown element when it sees the start tag of a “block” element p, h1, div, and so forth.
According to the W3 Schools stats, Firefox 2 only has around 3% of the market — perhaps low enough to justify ignoring it. It’s safe to assume that Camino 1 commands an even smaller percentage of the market.
By ignoring this issue, however, a site can look quite bad in these browsers. So how can we fix it?
The bug surfaces when Gecko doesn’t recognise an element. Explained roughly, when Gecko parses an unrecognised element, it removes the element’s contents and puts them next to the element.
Take, for example, the following code:
<body>
<header><h1>Title</h1></header>
<article><p>...</p></article>
</body>
This will be parsed in Gecko (prior to version 1.9b5) as if the markup were actually as follows:
<body>
<header></header>
<h1>Title</h1>
<article></article>
<p>...</p>
</body>
The visual result is similar to the above screenshot of IE running without JavaScript (though subtly different, as the DOM tree is actually in a different order than you as the author intended).
The fix
There are two approaches to fixing this issue, and so far I've only successfully used the non-JavaScript approach.
The JavaScript solution
The first approach is to use JavaScript to traverse the DOM tree, rearranging elements as issues are encountered. Simon Pieters has a small working example of how this can be done (towards the bottom of the page). In practise, however, I personally found it didn't work for my markup. The problem is definitely solvable using JavaScript, but this solution still needs work to handle all permutations of markup.
The XHTML solution
The second approach is to serve Gecko XHTML. I've found this to be the easier approach if you're either generating a page dynamically (using something like PHP) or if you can create your own .htaccess file to use Apache's mod_rewrite.
The first change to your markup is to add the xmlns attribute to your <html> tag:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
Next, we need to sniff the user agent string (typically a bad approach, but justifiable when targeting such a specific group of users). If the Gecko build is less than 1.9, then we need to set the Content-type header to application/xhtml+xml.
If you want to use mod_rewrite in an .htaccess file (or the httpd.conf file), you need the following rules:
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{HTTP_USER_AGENT} rv:1\.(([1-8]|9pre|9a|9b[0-4])\.[0-9.]+).*Gecko
RewriteRule .* - [T=application/xhtml+xml]
This rule sends the proper Content-type header to all Gecko based browsers where version is less than 1.9, or "rv:1.9pre" or "rv:1.9a" or "rv:1.9bx" where x is less than 5.
If you don't want to use the mod_rewrite approach, you'll need to manually send the header in your server side scripts. Here's a solution for a PHP script:
if (preg_match('/rv:1\.(([1-8]|9pre|9a|9b[0-4])\.[0-9.]+).*Gecko/', $_SERVER['HTTP_USER_AGENT'])) {
header('Content-type: application/xhtml+xml');
}
This snippet needs to be included before anything has been printed by your script — i.e., as early as possible.
Gotcha: Yellow Screen of Death
The Yellow Screen of Death shows up whenever there's an XML error on the page. If we're serving markup as XML and telling the browser to interpret it strictly as XML, then we can't serve any characters it doesn't recognise or else it's going to bork:

Below are a few ways to avoid XML parsing errors.
Create strict markup
You need to ensure your markup is squeaky clean — but that's easy, because you're already a Markup Jedi, right?
Use XML entities
HTML entities are a no-no. Sorry, but • isn't going to fly anymore. You need to use XML entities, the numerical representation of these characters.
I've built an entity lookup tool that shows the HTML entity and the XML value of that entity. For example, • is 8226, so the XML entity is •.
Sanitise user generated content
If your site relies on any user generated content (e.g., blog comments), then you need to sanitise the output to ensure there are no validation issues to trigger the Yellow Screen of Death.
This issue alone may justify further investigation of a JavaScript solution.
Worth the trouble?
All that said, Firefox has a very good automated upgrade path. Looking at the stats on W3Schools, it's safe to say that the number of users with this Gecko bug is rapidly diminishing.
58 Responses to “ How to get HTML5 working in IE and Firefox 2 ”
Comment by Ryan Roberts at
Great article, this has cleared up a few mind boggling issues I’ve had with Firefox 2. I already knew about the IE fix but your Javascript file looks even better.
Comment by Paul Lloyd at
After this weekend’s standrads.next meet-up, I wondered whether there was an alternative workaround to the IE issue, by using IE’s HTC (HTML Components) functionality. Quickly looking over the documentation I was able to find that you can create new elements with this tool, but they have to be name spaced. I only know enough to be dangerous however – is there any milage investigating a solution that follows this route at all?
Comment by Greg Hemphill at
This IE hack looks very promising… makes me think using html 5 is going to be a viable option sooner than I had thought.
Comment by Anon at
Your link for ‘a-grade browsers’ is broken…
Comment by Remy Sharp at
@Paul – I know what you mean about the HTC solution, and there are a couple of “solutions” to getting HTML5 elements to being styled without JavaScript.
First up – HTC, Dean Edwards’
<abbr>solution, but it requires the markup to be prefixed withhtml:. Frankly, if I have to prefix every element withhtml:it’s going to really mess with the markup, and having to maintain itThe second solution was via the WHATWG blog, which does work for a certain amount of markup, but as Simon points out, it’s not particularly scalable, specifically, you still can’t style the HTML5 elements, only those elements within those new elements, i.e. you can style:
using:
Comment by Dylan Parry at
I’m probably alone here, but I really don’t understand what you’re trying to say in the section “A LITTLE HEAD IS ALWAYS GOOD”. The link to a further explanation, with examples, left me even more confused than before I’d read it!
Comment by Ken at
“If you create the new element, and don’t use a tag (which is perfectly valid), IE will put all those created elements inside the tag.”
I’ve read this sentence 10 times and I still have no clue what it means. (There’s no tag, but it puts elements in … what?)
Comment by Remy Sharp at
@Dylan + @Ken – damn, some markup has been stripped from the post. It’s missing the word <head> before the word ‘tag’ in both instances. I’m updating the post now to get the code back in.
Comment by Sven at
Actually, & is a bad example for an invalid HTML entity because it is also a XML entity and every parser should understand it (the other XML entities are ", ', < and >). But you could always use the numerical entities, of course.
Comment by Disfruta de HTML5 en Internet Explorer y Firefox 2 | aNieto2K at
[...] sus nuevas capacidades. Y es que cada vez más los navegadores lo están adoptando, aunque aún es muy pronto para poder usarlo libremente sin preocuparnos de navegadores menos modernizados (IE8 e inferiores, Firefox [...]
Comment by Disfruta de HTML5 en Internet Explorer y Firefox 2 : Blogografia at
[...] sus nuevas capacidades. Y es que cada vez más los navegadores lo están adoptando, aunque aún es muy pronto para poder usarlo libremente sin preocuparnos de navegadores menos modernizados (IE8 e inferiores, Firefox [...]
Comment by pligg.com at
Get HTML5 working in IE…
If your wanting to start using HTML5 and have your site work in IE also, this post will help you learn how to make that happen. Go HTML5!…
Comment by How to get HTML5 working in IE and Firefox 2 « Jasper Blog at
[...] Read more: <html>5doctor [...]
Comment by » HTML5: naudoti negalima laukti - Kaip tapti ekspertu? at
[...] taipogi nenori pripažinti naujų žymų ir pritaikyti joms stilių, tačiau tai nesunkiai išsprendžiama Javascript pagalba. Jeigu vien Javascript sprendimas netenkina (unobtrussive, progressive enhancement, etc) – [...]
Comment by Torrance at
Erm, let me escape my tags. That should have read:
If you create the new element, and don’t use a <BODY> tag (which is perfectly valid), IE will put all those created elements inside the <head> tag. Pretty crazy, but something that’s easily avoided if you always use the <BODY> tag in your markup
Comment by John Resig - HTML 5 Parsing at
[...] there you can check the site HTML 5 Doctor for additional details on how to get the new HTML 5 elements working in all [...]
Comment by Remy Sharp at
@Torrance – darnit! You’re right, thanks – corrected!
Comment by Lewis Litanzios at
‘A little head is always good’ – you joker, haha. Cheers for ya time.
Comment by Delicious Bookmarks (2009-07-04 - 2009-07-09) | Josh Babetski : Quixotic Bravado at
[...] How to get HTML5 working in IE and Firefox 2 | HTML5 Doctor [...]
Comment by Eternal Moonwalk, HTML 5 Doctor and more | Engage Interactive Blog | Web design Harrogate at
[...] got an especially useful article about implementing HTML5 on Internet Explorer 6/7 and Firefox 2, so there’s no real excuse not to start embracing the technology, even on commercial [...]
Comment by eric at
ie hack, bleh.
I’m just going to make a HUGE red error div at the top of my website for IE viewers telling them basically “gg dipship, you’re using ie, here’s a link to firefox.”
Comment by zcorpan at
& does fly because it’s one of the five predefined entities in XML.
There are also another possible replacement for HTML entities in XML: just straight characters. There’s no need to escape non-ASCII if you’re using UTF-8.
Comment by zcorpan at
s/&/&/
Comment by Remy Sharp at
@Zcorpan – darn, I was going to use • as the example, but I wasn’t sure if people would know what I meant. I’ll change the article to correct it.
Regarding leaving the characters as plain – I couldn’t get this to work – and it threw up the yellow screen of death (this was with http://full-frontal.org which uses UTF-8 encoding). If you have an example of this working, then I’ll update the post. It might be because my page is a polyglot document (works as both XHTML and HTML 5) but I doubt if this is the cause.
Thanks for the catch!
Comment by How to get HTML 5 working in IE and Firefox 2 // HTML Five at
[...] HTML5 Doctor writes a detailed article on how to get HTML 5 working in IE and Firefox 2. [...]
Comment by DOM vs namespace pour implémenter HTML5 sur IE6, IE7, Firefox2, Camino, etc. at
[...] point sur les avantages et inconvénients de ces deux techniques, voici l’excellent article How to get HTML5 working in IE and Firefox 2 suggéré par Adrien Leygues dans le fil de discussion en [...]
Comment by Paymeplease at
I must agree the Hack looks very promising
Comment by Cool articles – SEO, blogging, internet marketing(july13-july19 2009) « Stefanm, my link collection at
[...] How to get HTML5 working in IE and Firefox 2(IE doesn’t style HTML5 elements, Firefox 2 and Camino rendering bug); [...]
Comment by HTML5 Tips: structral elements, Doctype and ARIA » iheni :: making the web worldwide at
[...] 2 and Camino can be fixed using JavaScript or by serving Gecko XHTML. Getting HTML5 working on IE and Firefox 2 from HTML Doctor has a good article about how to do [...]
Comment by CaoInteractive Blog » Blog Archive » 23 Essential HTML 5 Resources at
[...] How to get HTML5 working in IE and Firefox 2 – Another great article from HTML 5 Doctor [...]
Comment by Adam at
Is there a way to stop IE complaining about the script activex security risk when defining the html5 elements it doens’t know yet?
Comment by BWS Blog » Blog Archive » We are CSS 2.1 Complient!!!! – HTML5 possibillities!!!! at
[...] the HTML5 IE issues it would be best to check out: How to get HTML5 working in IE and Firefox 2. This should help solve a lot of issues and problems that IE presents when trying to render the [...]
Comment by Web Standards, Accessibility & More » HTML 5 Resources at
[...] How to get HTML5 working in IE and Firefox 2 [...]
Comment by HTML 5 Resources « AccessTech News at
[...] How to get HTML5 working in IE and Firefox 2 [...]
Comment by HTML 5 Resources « The BAT Channel at
[...] How to get HTML5 working in IE and Firefox 2 [...]
Comment by Defining The Vomit Bug at
[...] The old Gecko engine (for Camino and Firefox 2) suffers from the same vomit bug when introducing new (or HTML5) elements (which can be fixed by serving as XHTML). [...]
Comment by Arlen at
@paul – You can create elements inside the htc, but the existence of those elements doesn’t get passed out to the rendering engine without namespacing. So, I thought, why not simply create the new elements for the doc tree *inside* the HTC. Can do that, *and* those new elements can be seen and styled as HTML5 elements by the rendering engine. Success? Not quite. Because the new elements lack content, and since the unknown elements don’t exist in the DOM tree, you can’t copy the content from them into your newly created and styled elements from the HTC.
Bottom Line: If you wrote the content using div class=”html5name” an HTC could walk the tree and replace all the classed divs with the HTML5 elements, including their content, and CSS selectors based on HTML5 elements would find and style them. A lot of work for an IE-only solution, and that forces yu to send it non-html5 content.
Comment by protofunc() » Meinung zu HTML5 at
[...] bzw. zu nutzen empfehlen. Die tollen HTML5-Elemente (nav, aside, header, footer..), die wir mit dreckigen Tricks nutzen könnten, bringen nichts. Kein Browser, kein Screenreader und auch keine ernstzunehmende [...]
Comment by 25+ Great HTML 5 Resources to Get You Started | tripwire magazine at
[...] How to get HTML5 working in IE and Firefox 2 [...]
Comment by Twitter Trackbacks for How to get HTML5 working in IE and Firefox 2 | HTML5 Doctor [html5doctor.com] on Topsy.com at
[...] link is being shared on Twitter right now. @wevertonribeiro said Testando o HTML 5 no IE e firefox [...]
Comment by CodeJoust at
If you wish to streamline the creation of the xhtml5 elements consider putting them in a loop.
var el = ['section','date','aside']; for(x=0;x<el.count;x++){document.createElement(el[x]);}
Comment by HTML 5 at
[...] This solution seems like a good one, but it is not perfect, so you need to go a bit further if you want to achieve support in older browsers. The problem is that some browsers (such as Firefox 2, Camino 1, and all versions of Internet Explorer) don’t see the HTML 5 elements as unrecognised; they don’t see them at all! So text marked up with an HTML 5 element can’t be styled at all in these browsers, because the elements don’t exist in their eyes. There is a workaround for this, and it is explained in the HTML 5 doctor article How to get HTML5 working in IE and Firefox 2. [...]
Comment by andrew brundle at
<style>
HEADER, FOOTER, NAV, SECTION, ARTICLE{display:block}
SECTION, .section{width: 1000px}
</style>
<section>
<!–[if IE]><div class="section"><![endif] –>
<!–[if IE]></div><![endif] –>
</section>
Comment by andrew brundle at
I just posted the code snippet above to see how it looks on this blog. It seems okay!
Anyway, this is the sort of code I personally will use. No JS, and it will work in IE.
Messy, sure. But functional.
Comment by pieroxy at
While not exactly on topic, I would suggest that people start using the “ie no more” or the ‘IE awareness initiative” (my website) to try to get rid of the old and unmanageable versions of IE as soon as possible. While pretty intrusive, these initiatives can at least inform people that there are alternatives to using IE6 !
Comment by links for 2009-10-08 | Brilang.com at
[...] How to get HTML5 working in IE and Firefox 2 | HTML5 Doctor (tags: html5) [...]
Comment by Blog HTML5 – Également sur CSS3, le design Web et les standards » HTML5 Hack pour Internet Explorer (Partie 2) at
[...] aussi cet article d’HTML5 Doctor qui explique comment utiliser HTML5 sous Firefox 2 et [...]
Comment by HTML 5 in Internet Explorer « DREWspective at
[...] there is a JavaScript hack that solves the problem, which I’ve just applied to the site. addthis_url = [...]
Comment by Simon at
can’t you just type its instead of it’s?
Comment by Lee at
For the Firefox 2 and Camino fix, does this then require all self closing elements to be written in an XHTML style with trailing slashes if it’s being served as XHTML?
Comment by Collection of HTML5 Resources to Move You Forward at
[...] How to get HTML5 working in IE and Firefox 2 [...]
Comment by More HTML5 Resources » Free Xenon Consulting at
[...] How to get HTML5 working in IE and Firefox-2 (@ HTML Doctor) [...]
Comment by How to get HTML5 working in IE and Firefox 2 « Web Developer Blog at
[...] Click here to read full article [...]
Comment by IE6 Hacks And Fixes | Morgan Web Design at
[...] HTML5 For IE – http://html5doctor.com/how-to-get-html5-working-in-ie-and-firefox-2/ [...]
Comment by Web News and Practical websites » In Depth: Everything you need to know about HTML5 at
[...] Camino has version 2 in beta, but it hasn’t been released just yet (and arguably, it’s not an A-grade browser). However, there are a few ways to fix Firefox 2 and Camino 1 and you can read about them here. [...]
Comment by DOM vs namespace pour implémenter HTML5 sur IE6, IE7, Firefox2, Camino, etc. -- css 4 design at
[...] point sur les avantages et inconvénients de ces deux techniques, voici l’excellent article How to get HTML5 working in IE and Firefox 2 suggéré par Adrien Leygues dans le fil de discussion en [...]
Comment by Wiechu at
All the time – all about… IE. You are taking so much care for this app. It must be really good browser.
Comment by stoyv at
PHP Forms – The best form creator & processor solution since 2003
Create any kind of web form in several mouse clicks! Generate a code that can be easily copied and pasted to any web page