Required elements and optional tags in HTML

In HTML, some elements have optional tags. In fact, both the opening and closing tags of some elements may be completely removed from an HTML document, even though the elements themselves are required. Does that seem a bit confusing?

It can seem strange, especially considering that three required HTML elements whose start and end tags are optional are the html, head, and body elements. Yes, you can leave those out of your markup in HTML (but not in XHTML). The browser will still create the elements, and they will be available in the document tree.

Still confused? Read Gez Lemon’s detailed explanation in Required Elements, and Required Tags.

Posted on December 22, 2005 in (X)HTML, Quicklinks

Comments

  1. December 22, 2005 by Florian

    I’m not sure if the use of this minimised markup is still legal … Anne considered to patent it! :)

  2. IMHO, this is not something we should be encouraging.

  3. December 22, 2005 by Roger Johansson (Author comment)

    Scott: I agree, but it’s important to know about this.

    The only reason for omitting the html, head, and body tags I can see is if you really, really need to save every possible byte of bandwidth.

  4. There are other required elements that aren’t touched on in the article, the most signifigant being <tbody>. When traversing a DOM tree to work with a table, it’s important to remember that it’s inserted into the DOM, even if it’s not in the markup.

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.