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.

  • December 22, 2005
  • Comments closed
  • Posted in

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. December 22, 2005 by Scott

IMHO, this is not something we should be encouraging.

3. December 22, 2005 by Roger Johansson

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. December 23, 2005 by Michael Newton

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.

Sorry, comments are closed for this post.

Information, sponsorship, and externals

Subscribe

SidebarAds

Looking for web hosting?

Try DreamHost!

Use the promo code 456BEREASTREET3 to save USD 20 when you sign up!

Favourites, here and elsewhere

Affiliation

  • NetRelations
  • Kaffesnobben
  • Dagens recept
  • 9rules network member

Support this site

Show your support by buying a book or two from SitePoint or getting me something from my Amazon Wish List.