Supporting New Elements in IE

January 7th, 2009 by Lachlan Hunt

Internet Explorer poses a small challenge when it comes to making use of the new elements introduced in HTML5. Among others, these include elements like section, article, header and footer. The problem is that due to the way parsing works in IE, these elements are not recognised properly and result in an anomalous DOM representation.

To illustrate, consider this simple document fragment:

<body>
  <section>
    <p>This is an example</p>
  </section>
</body>

Strangely, IE 6, 7 and 8 all fail to parse the section element properly and the resulting DOM looks like this.

  • BODY
    • SECTION
    • P
      • #text: This is an example
    • /SECTION

Notice how IE actually creates 2 empty elements. One named SECTION and the other named /SECTION. Yes, it really is parsing the end tag as a start tag for an unknown empty element.

There is a handy workaround available to address this problem, which was first revealed in a comment by Sjoerd Visscher. The basic concept is that by using document.createElement(tagName) to create each of the unknown elements, the parser in IE then recognises those elements and parses them in a more reasonable and useful way. e.g. By using the following script:

document.createElement("section");

The resulting DOM for the fragment given above looks like this:

  • BODY
    • section
      • P
        • #text: This is an example

This same technique works for all unknown elements in IE 6, 7 and 8. Note that there is a known bug that prevented this from working in IE 8 beta 2, but this has since been resolved in the latest non-public technical preview.

For convenience, Remy Sharp has written and published a simple script that provides this enhancement for all new elements in the current draft of HTML5, which you can download and use.

This script is not needed for other browsers. Opera 9, Firefox 3 and Safari 3 all parse unknown elements in a more reasonable way by default. Note, however, that Firefox 2 does suffer from some related problems, for which there is unfortunately no known solution; but it is hoped that given the faster upgrade cycle for users of Firefox, relatively speaking compared with IE, Firefox 2 won't pose too much of a problem in the future.

23 Responses to “Supporting New Elements in IE”

  1. Alexis Deveria Says:

    Good to hear that they fixed it in the latest IE8 preview, didn’t know that.

    Who knows, the final version might really surprise us and support unknown elements properly without the script. Thus allowing the use of these elements without the JS hack before, say, 2017.

  2. Weston Ruter Says:

    Firefox 2 seems to be able to style HTML5 elements just fine when being served XHTML. That’s what we at Shepherd Interactive have done with our own site and client sites like http://rebathoregon.com/ and http://theccaa.net/

  3. Ian Bicking Says:

    Do those elements then work with stylesheets, etc? Like, if I have a “section” selector in my stylesheet, IE applies that to the element?

  4. Anne van Kesteren Says:

    Ian Bicking, yes, that’s the idea.

  5. Ajaxian » Backwards compatibility and HTML 5 Says:

    [...] can get IE to support new tags as shown in this example by using [...]

  6. Backwards compatibility and HTML 5 | How2Pc Says:

    [...] can get IE to support new tags as shown in this example by using [...]

  7. HTML5: Neue Elemente beim Internet Explorer anmelden - Peter Kröner - Die Kunst des Machbaren Says:

    [...] Wunder dass man sowas nicht stylen kann. Dieses Problem lässt sich aber reparieren! Es ist sogar recht einfach, man muss das neue Element nur mit einer Zeile Javascript beim IE [...]

  8. Uxebu.com - JavaScript addicts » Supporting New Elements in IE Says:

    [...] Supporting New Elements in IE [...]

  9. Jeff Schiller Says:

    Thanks, I didn’t know that IE8 had fixed this issue, but very glad to hear it.

  10. Ook interessant | Scriptorama.nl Says:

    [...] Supporting new elements in Internet Explorer - Geen verrassing, maar Internet Explorer ondersteunt bijzonder weinig van HTML5, toch blijk je IE wel zover te kunnen krijgen dat je de nieuwe HTML element kunt gebruiken. [...]

  11. Neue HTML5-Elemente - Code Candies Says:

    [...] richtig zu erkennen und ins DOM zu rendern. Der Trick ist altbekannt, wird aber auch nochmal im WhatWG-Blog ausführlich beschrieben. Um den <section> im IE bekannt zu machen, reicht folgende Zeile Javascript: [...]

  12. Brad Neuberg Says:

    Actually, I believe that IE won’t correctly style elements even with this, and also nested content can get strange. However, you can use a Microsoft Behavior/HTC to have the tag be a true first class citizen of the DOM, CSS styleable, etc. It’s on my plate to write a blog post documenting how to do this.

  13. The WHATWG Blog » Blog Archive » Styling HTML5 markup in IE without script Says:

    [...] The WHATWG Blog Please leave your sense of logic at the door, thanks! « Supporting New Elements in IE [...]

  14. HTML 5 elements | Fyrdility Says:

    [...] these elements, Internet Explorer (through IE8) and Firefox (2 and lower). Thus, I am using the document.createElement JavaScript hack for IE. Reliance on JavaScript for styling is reason #1 not to try this at [...]

  15. Ajaxian » Styling HTML5 markup in IE Says:

    [...] Pieters first posted on how to support new elements in IE. “However, if the user has scripting disabled, the layout would probably fall apart [...]

  16. Styling HTML5 markup in IE | How2Pc Says:

    [...] Pieters first posted on how to support new elements in IE. “However, if the user has scripting disabled, the layout would probably fall apart [...]

  17. Redesigning with HTML 5 and WAI-ARIA | Neuronworks Blog, webMethods, Oracle, Bea, Java Dev2Dev, Arch2Arch Says:

    [...] There’s one gotcha about styling HTML 5 pages in IE: it doesn’t work. You can force it to quite easily with a JavaScript hack document.createElement(’element name’). (Lachlan Hunt gets to the bottom of why IE needs this.) [...]

  18. Stedders Says:

    Many thanks for this, have spent a couple of hours banging my head on the keyboard.

    Cheers
    Stedders

  19. The WHATWG Blog » Blog Archive » This Week in HTML 5 - Episode 21 Says:

    [...] Sharp’s HTML5 enabling script allows web authors to use HTML 5 elements that Internet Explorer doesn’t know about and still have them show up properly in the [...]

  20. The WHATWG Blog » Blog Archive » Supporting New Elements in Firefox 2 Says:

    [...] have previously talked about how to get Internet Explorer to play ball when using the new HTML5 elements, but today [...]

  21. Leif Halvard Silli Says:

    WHATwg promotes the DOM = you may drop actually inserting the tags for the body element, as the user agents inserts the body element anyhow.

    However, for new elements in Internet Explorer, if the document fails to have the body start tag and if the new element also has been “created” via document.createElement("newElementName");, then, in the DOM, the new element will actually (at least if it is supposed to be [one of] the first element[s] inside the body) be placed inside the head element.

    I created a demonstration in Live DOM viewer

    (Tested in IE 6, IE7 and IE8.)

    It has no effect if you properly use the head element tags - you have to insert the body start tag in order to be safe.

  22. zcorpan Says:

    Leif, yep, but this is not unique to the new elements in IE. Try this, for instance,

    <!doctype html>
    <title>test</title>
    <div><form>test</form></div>

    Believe it or not, but IE will actually put the form as child of head, body as child of form, and div as child of body. The body is also sibling of head.

    So, including the <body> tag is good advice if one wants a sane DOM in IE regardless of usage of the new elements.

  23. Webkrauts » html5gallery - Learning by Gucking Says:

    [...] Internet Explorer gilt dies leider wieder nicht. Wie so oft müssen wir hier wieder tief in die Trickkiste [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

purchase tramadol Carisoprodol Prescription order ultram; "hoodia gordonii" Phentermine Prices "vicodin prescription" 50 tramadol Order Carisoprodol Online Tramadol com tramadol hcl 991. cheap ambien Order Valium diet pills adipex cheap ultram; Vicodin For Sale Legal vicodin norco hydrocodone 927. order phentermine Phentermine Pharmacy order carisoprodol

phentermine sales,

Valium No Prescription ultram 50 mg phentermine prescriptions Xanax Xr phentermine without prescription ultram online Hoodia Gordoni ultram online tramadol 50mg, Buy Vicodin Online oxycodone vs hydrocodone 37.5 phentermine Phentermine Com vicadin xanax without prescription Ultram Buy hoodia weight buy lorazepam online

Hydrocodone Vicodin

tramadol prescription ionamin online Vicoden "hydrocodone 10" buy cheap soma Ultram Online phentermine for sale buy tramadol online Hydrocodone Lortab xanex, vicodin 500 Hydrocodone Pain "fastin" Cheapest phentermine com fastin 820. Phentermine Adipex hydrocodone drugs; phentermine on line Tramadol Sale ionamin diet pill buy xanax Buy Carisoprodol Online alprazolam online? rx phentermine; Order Valium Online alprazolam prescription, ionamin prescription Buy Ultram Online phentermine sale Buy valium online without a prescription order valium 315. Lorazepam Prescription ionamin diet pill alprazolam discount; Acomplia Hydrocodone apap hydrocodone canada 723. www ultram com Vicodin Hydrocodone adipex online phentermine on line 37.5 Phentermine "generic adipex" "buy zolpidem" Com Fastin order vicodin online order tramadol? Carisoprodol Soma drug fastin order alprazolam Adipex Pharmacy adipex p Hydrocodone apap hydrocodone canada 723. Hydrocodone buy phentermine online xanax prescription Vicodin Com ionamin diet pill purchase phentermine online Buy Ambien Online adipex pills purchase tramadol Ultram 50 Mg adipex no prescription Adipex adipex 37.5 992. Cheap Ultram buy ambien online adipex pills Xenical Prices online xanax! get phentermine Tramadol Cod Buy ativan online buy cheap xanax 352. buy carisoprodol online Ic Hydrocodone Apap buy soma discount carisoprodol Get Tramadol generic tramadol; fastin prescription! Darvocet Vicodin phentermine price discount valium online Cheap Adipex carisoprodol 350 compare phentermine Soma Prescription com fastin! xenical tablets Cheapest Tramadol Hydrocodone acetaminophen hydrocodone apap 843. ultram com Phentermine Hcl vicodin hp! adipex 37.5 50 Tramadol diazepam prescription order ultram online; Online Hydrocodone lorazepam online discount valium Buy Ativan tramadol rx buy carisoprodol Hydrocodone Cheap hydrocodone "get tramadol" Buy Cheap Tramadol tramadol sale ultram 50 Order Ativan ultram price phentermine on line Online Xanax adipex pill carisoprodol 350mg Overnight Tramadol "vicodin generic" online pharmacy phentermine Online Vicodin hydrocodone medication valium online; Vicodin Lortab cheap soma phentermine on line Buy Ambien order valium online xenical prices Phentermine Prescriptions alprazolam buy cheap adipex! Xenical Price phentermine price adipex com Ativan vicodin tablets, generic tramadol; Meridia Phentermine cheap valium drugs vicodin Alprazolam 2mg ionamin ic hydrocodone apap Order Soma order valium online discount phentermine Buy Cheap Phentermine low cost phentermine adipex 37.5 mg Diazepam 10mg xanax pharmacy vicodin com Ionamin medication tramadol, generic ambien Phentermine Diet Pill xanax no prescription discount soma Soma Pharmacy ultram er! generic hydrocodone, Tramadol Hcl order ultram; overnight tramadol Xenical Pill vicodin for sale order xanax Alprazolam 0.5mg cheap soma Phentermine diet phentermine diet pill 186. Buy Lorazepam Online phentermine 90 Phentermine weight loss phentermine without a prescription 989. Buy Tramadol Online buy lorazepam online "generic adipex" Phentermine On Line ultram tramadol hcl? Buy Soma Online phentermine hcl tramadol hydrochloride Hydrocodone 7.5 xanax prescription online vicodin Adipex Com xanax drug buy valium no prescription Zolpidem ambien online hydrocodone pill Vicodin 500 tramadol sale "www adipex com"
Hydrocodone Apap
tramadol alprazolam online pharmacy; Ultram Prescription ativan lorazepam tramadol sale Diet Adipex phentermine on line vicodin Legal Vicodin compare phentermine adipex sale Hydrocodone Mg tramadol pharmacy

alprazolam generic

Ultram Er

diazepam 5mg ambien generic Hydrocodone Acetaminophen xanax drug Hydrocodone pain hydrocodone pill 870. Hoodia Weight tramadol hcl? order valium online Tramadol Pharmacy ultram com

Legal vicodin norco hydrocodone 927.

Phentermine Capsules "vicodin prescription" vicodin com Hydrocodone For Sale Tramadol com tramadol hcl 991. cheap ambien Phentermine Price diet pills adipex cheap ultram; Cheap Soma Legal vicodin norco hydrocodone 927. order phentermine Ultram order carisoprodol phentermine sales, Adipex Ionamin ultram 50 mg prescription phentermine Diazepam Pharmacy phentermine without prescription ultram online Hydrocodone 500 ultram online tramadol 50mg, Get Phentermine oxycodone vs hydrocodone adipex no prescription Tramadolultram vicadin xanax without prescription Cheap Tramadol hoodia weight buy lorazepam online Fastin Prescription tramadol prescription phentermine 90 Order Tramadol "hydrocodone 10" buy cheap soma Generic Hydrocodone phentermine for sale buy tramadol online Generic Valium xanex, vicodin 500 Diazepam 5mg "fastin" Cheapest phentermine com fastin 820. Buy Alprazolam Online hydrocodone drugs; phentermine on line Adipex Without Prescription ionamin diet pill buy xanax Phentermine Without A Prescription alprazolam online? purchase phentermine
Alprazolam Prescription
alprazolam prescription, hoodia diet pill

Buying Vicodin

Buy valium online without a prescription order valium 315. diet pills phentermine Vicodin Prescription alprazolam discount; Hydrocodone apap hydrocodone canada 723. Hydrocodone Medication www ultram com adipex online Ativan Prescription phentermine on line "generic adipex" Taking Phentermine diazepam 10mg online vicodin Xenical Sales order tramadol? drug fastin Buy Xanax Online order alprazolam adipex p Purchase Tramadol Hydrocodone apap hydrocodone canada 723. buy phentermine online Purchase Hydrocodone xanax prescription ionamin diet pill Phentermine Canada www adipex! adipex diet pill Phentermine 15 purchase tramadol adipex no prescription Adipex Drug Adipex adipex 37.5 992. buy ambien online Xanax Com adipex pills online xanax! Ionamine get phentermine Buy ativan online buy cheap xanax 352. Order Adipex buy carisoprodol online buy soma Hydrocodone Canada generic soma generic tramadol; Buy Zolpidem fastin prescription! phentermine price Ultram Tramadol discount valium online carisoprodol 350 Drugs Vicodin compare phentermine buy phentermine online No Prescription Phentermine xenical tablets Hydrocodone acetaminophen hydrocodone apap 843. Buy Carisoprodol ultram com vicodin hp! Www Adipex adipex com diazepam prescription Carisoprodol 350mg order ultram online; lorazepam online Alprazolam 1mg discount valium tramadol rx Ultram Pharmacy buy carisoprodol hydrocodone Online Pharmacy Phentermine "get tramadol" tramadol sale Tramadol Online ultram 50 ultram price Xanex phentermine on line adipex pill Generic Xanax carisoprodol 350mg vicodin for sale Valium online pharmacy phentermine hydrocodone medication Generic Soma valium online; cheap soma Prescription Adipex Online phentermine on line order valium online Vicodin Medication xenical prices alprazolam buy Hoodia Diet cheap adipex! phentermine price Buy Valium Online Without A Prescription adipex com "vicodin prescription" Hydrocodone Pill generic tramadol; cheap valium Vicodin Without Prescription drugs vicodin ionamin Ativan Com ic hydrocodone apap order valium online Xanax Without Prescription discount phentermine low cost phentermine Alprazolam adipex 37.5 mg xanax pharmacy Adipex No Prescription vicodin on line medication tramadol, Buy Ionamin Online generic ambien xanax no prescription Www Ultram Com discount soma ultram er! Buy Ativan Online generic hydrocodone, order ultram; Xanax Prescription overnight tramadol vicodin for sale Alprazolam Xr order xanax cheap soma Generic Tramadol Phentermine diet phentermine diet pill 186. phentermine 90 Xanax 1mg Phentermine weight loss phentermine without a prescription 989. buy lorazepam online Www Alprazolam "generic adipex" ultram 2mg Xanax tramadol hcl? phentermine hcl Order Ultram tramadol hydrochloride xanax prescription Phentermine 30mg online vicodin xanax drug Hoodia Gordonii buy valium no prescription ambien online Alprazolam Discount hydrocodone pill tramadol online Buy Cheap Xanax "www adipex com" overnight tramadol Buy Hydrocodone Buy ativan online buy cheap xanax 352.

"));