Jens Meiert

Optional Tags in HTML 4

Jens Meiert, June 1, 2008.

This entry is filed under Web Development.

For convenience and in order to allow for additional bits or bytes being saved in your markup, here’s a list of all optional tags according to the HTML 4.01 Strict DTD. Finally, as even nine years after release of the HTML 4 specification, there still seems to be no list like this.

These are in fact tags, not elements, and for some this list might explain the simplicity of the supposedly best HTML template. However, thanks to Rupert for inspiring me to compile such a list. And I’ll eventually extended it (HTML 5, anyone?).

Read More

Enjoy the most popular posts, probably including:

Comments

  1. On June 1, 2008, 16:27 CEST, johno said:

    Thanks for compiling the list. At last, I know the difference between a tag and an element.

  2. On June 2, 2008, 4:48 CEST, Duluoz said:

    Just curious…. Why do you construct your blog with XHTML markup verses HTML?

  3. On June 2, 2008, 7:28 CEST, Philippe said:

    Some endtags are explicitly forbidden, like this or this one or that one, according to the HTML 4.01 spec. Granted, the wording of the DTD is not as clearcut.

    Nitpicking ? You’ll be the judge… :-).

  4. On June 2, 2008, 11:26 CEST, Jens Meiert said:

    John, you’re welcome :)

    David, basically because of cost of problem vs. cost of solution considerations, especially since my blog uses Wordpress (which in turn uses XHTML by default).

    Philippe, good point. However, I just grabbed all optional tags, where the optional start and end tags of e.g. body, head, and html are certainly of most interest (as opposed to </img>, for example).

  5. On June 2, 2008, 16:19 CEST, Gunnar Bittersmann said:

    IMHO, the most useful statement about optional tags is missing here: not to make use of the option of leaving them out (for that only makes the HTML source unclear, thus harder to read and more vulnerable to errors).

    “[…] to allow for additional bits or bytes being saved”? No, thank you, that’s a too heavy price for a questionable gain.

  6. On June 2, 2008, 17:02 CEST, Duluoz said:

    @Jens - I have a horrible memory! I think I read that post last year…HA!

    I really only asked the question to see if your answer is what you already stated in your 2007 post. I think I subconsciously had that post in mind! I too came to the same conclusions for project at work. Glad to know I made the same decisions for the same reasons as yourself. ;)

  7. On June 5, 2008, 10:43 CEST, Jens Meiert said:

    Gunnar, why should omitting something make anything more unclear or harder to read? I guess I do not need to set up examples for that but instead may keep it short and claim that it’s quite the contrary.

    David, yah, glad to hear that :) Idealism is a nice currency but you cannot necessarily buy everything with it.

  8. On June 5, 2008, 12:34 CEST, Anne van Kesteren said:

    FWIW, some of these tags are not optional, they are simply not allowed (do not exist, if you will), such as </br> and </hr>.

    (HTML5 will indeed add more empty elements, such as command, event-source, and source.)

  9. On June 5, 2008, 12:51 CEST, Jens Meiert said:

    Thanks for dropping by, Anne; I know, for clarity’s sake I probably shouldn’t have grabbed just everything that was declared optional in the DTD. But, most people will figure out that this list is not about </link> and </meta> ;)

  10. On June 5, 2008, 17:22 CEST, Gunnar Bittersmann said:

    @Jens:
    I tend to disagree. Let me give an example:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <title>Example</title>
    <script type="text/javascript" src="myScript1.js"></script>
    <p id="myParagraph1">Some text.
    <script type="text/javascript" src="myScript2.js"></script>
    <p id="myParagraph2">More text.
    <ul>
    <li>some list item
    <li>another one
    </ul>
    <p id="myParagraph3">Yet more text.

    Where exactly does the body element begin? Where exactly does the p[@id="myParagraph1"] element end?

    You need a lot of knowledge about HTML to answer these questions. The element tree is not always as one has expected (what becomes noticeable when styling the document). Spotting one’s errors is difficult since a validator can’t help. Not so if you write all closing tags.

    A very common error is trying to append a tr element as a child to a table element with JavaScript. The source code
    <table>
      <tr>
        <td>foo</td>
      </tr>
    </table>

    leads one to think that tr was a child of table which is never the case in HTML; there is always a tbody element in between.

    My advice: Never omit optional tags. Don’t write HTML 4.01, do write XHTML 1.0.

  11. On June 6, 2008, 11:05 CEST, Alan Gresley said:

    If implementations decides to repair tag soup forever, where will the web go?

    I want a unforgiving browser. Where do I find one? :-)

  12. On June 6, 2008, 11:12 CEST, Alan Gresley said:

    @Duluoz

    Just curious…. Why do you construct your blog with XHTML markup verses HTML?

    Why not use XHTML. My own personal choice of language to code web pages.

    Look at where Eric Meyer wants HTML5 to go. href on many elements.

  13. On June 9, 2008, 19:56 CEST, Jens Meiert said:

    Gunnar, I agree that omitting tags is not necessarily for beginners. However, the parsing rules are clear on these cases. Concerning the tbody element, well, I do not disagree that forgetting about it in scripting context seems to happen, but it’s just that tbody is optional in XHTML as well.

    Alan, use Netscape 4, probably still the browser known to be “most unforgiving” ;)

Leave a Comment

Leave a Comment

Respect the comment guidelines. XHTML allowed: <a href=""> <abbr title=""> <blockquote> <code> <em> <strong>

Found a mistake? Reward! Email me, jens@meiert.com.

You are here: meiert.com – Archive for 2008 – Optional Tags in HTML 4

Last update: June 1, 2008. Copyright 2000-2008 Jens Meiert. Legal notice.