Anne van Kesteren

<html id="">

I made two really easy test cases for checking if the id attribute is allowed on the html element (aka the root element). One for XHTML 1.0 (Strict off course) and one for XHTML 1.1.

Test cases are gone.

I wonder why this is invalid. You would think it's perfectly valid, but strange enough it isn't for XHTML 1.1 (the one I'm using). Is the validator mistaking, or did they change more than they addressed.

I now know the reason why it isn't allowed after searching on google for "id attribute" "html element" "xhtml 1.1" -name -frames. I found a list archive of the W3C where Björn Höhrmann explains:

HTML 4.01 does not allow <html> to have an id attribute, neither do XHTML 1.0 First Edition or XHTML Modularization (the latter allows at most dir, lang, xmlns, xml:lang and version). XHTML 1.1 is based on XHTML Modularization and thus disallows <html id='...' ...>.

XHTML 1.0 Second Edition had been changed in this respect and allows the html element to have an id attribute. Take a look at the html element in:

[ LINK ]


  1. Maybe it's invalid because you can only have one <html> in your XHTML source. Assigning an id would then be a strange thing to do. It could also be an error of the validator, of course. Maybe no-one anticipated this at the W3C.

    (Posted using Mozilla on SuSE 8.2; woohoo!)

    Posted by Bas Hamar de la Brethonière at

  2. Maybe it's invalid because you can only have one <html>

    Jup, but if you have 2 pages that uses the same stylesheet and you want for page 1 id nr 1 and page 2 id 2.

    Posted by WousseR at

  3. Jup, but if you have 2 pages that uses the same stylesheet and you want for page 1 id nr 1 and page 2 id 2

    in that case you can use <body class=""> or <body id=""> see

    Posted by george at

  4. @George, I removed the other 2 comments, 'cause they where the same.

    I know about giving the element body an id attribute, but what if you want to style the root element?

    Posted by Anne at

  5. How does "styling the root element" differ from "styling the body element"? Is there something that can be achieved with the former that cannot be achieved with the latter? (Indeed, shouldn't they act identically?)

    Posted by Jacques Distler at

  6. You told me it could be a Mozilla bug, but with absolute positioned layouts (and application/xhtml+xml) the body element becomes a div element and is therefore not useful for applying a background to the page.

    With the root element it is still possible.

    Posted by Anne at

  7. When you say that, with application/xhtml+xml.

    the body element becomes a div element

    I'm not quite sure what you mean by that. As near as I can figure, your complaint is that the size of the body element is calculated incorrectly (at least, in Mozilla) when it has absolutely-positioned child elements. I believe you; I just think that's a bug.

    Posted by Jacques Distler at

  8. Ok I searched Bugzilla for this, and I found a bug and a related comment:

    So I think I was right in this one, because you and me have a XML document and not a HTML document.

    Posted by Anne at

  9. Sorry 'bout the HTML. I saw styled comments above and guessed that it was allowed. (It's nice to explicitly state what is and is not allowed in comments, especially since you don't have a "preview" button.)

    As to body versus root element, it appears you are correct. In XHTML, the body element does not fill the viewport.

    Mozilla may or may not propagate the background of the body element to the root element. That appears to happen in the case of my blog. But perhaps I am relying on Bug 214969?

    Now I am in a quandary. Putting a background-image on both the html and body elements won't work right in general (they won't necessarily line up correctly).

    But certain (unmentionable) broken browsers won't deal correctly with a background-image on the html element. Grrr...

    Posted by Jacques Distler at

  10. You could use this:

     background:#f1f1f1 url(/weblog/images/bg.gif) fixed;

    I use it myself and it works for every browser I tested this site in.

    Posted by Anne at

  11. Remark: The solution above doesn't work in Opera 6/7.

    Posted by Thiemo at