Optional Tags in HTML 4

Published on June 1, 2008 (ā†» February 5, 2024), filed under (RSSĀ feed).

This and many other posts are also available as a pretty, well-behaved ebook: On Web Development.

For your convenience, hereā€™s a list of all optional tags according to the HTML 4.01 Strict DTD. Omitting these tags allows to save markup and thus file sizeā€”if you choose to. I created this list because even nine years after release of the HTML 4 specification, there still is no list like this.

These are indeed tags, not elements. The list might explain the simplicity of the supposedly best HTML template. Thanks Rupert for the inspiration, and others for the encouragement to extend it (HTML 5? [which I made available 11 years later]).

Toot about this?

About Me

Jens Oliver Meiert, on September 30, 2021.

Iā€™m Jens, and Iā€™m an engineering lead and author. Iā€™ve worked as a technical lead for companies like Google, Iā€™m close to W3C and WHATWG, and I write and review books for Oā€™Reilly and Frontend Dogma. I love trying things, not only in web development, but also in other areas like philosophy. Here on meiert.com I share some of my views andĀ experiences.

If you have a question or suggestion about what I write, please leave a comment (where applicable) or aĀ message.

Comments (Closed)

  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 Oliver Meiert said:

    David, because of cost of problem vs. cost of solution and because my blog uses WordPress (which uses XHTML by default).

    Philippe, good point. I just grabbed all optional tags, where the optional start and end tags of e.g. body, head, and html are probably 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 Oliver Meiert said:

    Gunnar, why should omitting something make anything more unclear or harder to read?

    David, glad to hear that šŸ˜Š Idealism is a nice currency but you cannot 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 Oliver 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, people may 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 September 3, 2008, 18:13 CEST, Thorsten said:

    I stumbled across this post some days ago and in the meantime also found a list on the W3C homepage including the same information.

  14. On February 17, 2009, 0:38 CET, cid said:

    @Philippe

    ā€ Granted, the wording of the DTD is not as clearcut.ā€

    Itā€™s clearcut, given that the spec defines how element declarations
    should be read:

    This example illustrates the declaration of an empty element type:

    <!ELEMENT IMG - O EMPTY>

    The element type being declared is IMG.
    The hyphen and the following ā€œOā€ indicate that the end tag can be omitted, but together with the content model ā€œEMPTYā€, this is strengthened to the rule that the end tag must be omitted.

    I donā€™t understand why Jens included empty elements in this list.

  15. On February 23, 2009, 17:00 CET, cid said:

    @Jens

    I donā€™t think it was confusing, you consistently referred to elements with ‘ - O ‘ MIN field.

    The point is the DTD, in fact, does not declare those tags optional just because ‘ - O ‘ is in the MIN field as ‘ - O ‘ and ‘ - O EMPTY ‘ donā€™t mean the same as far as the end-tag is concerned.
    In HTML DTDs the two minimization parameters are required in all element declarations even when the end-tag is prohibited by the SGML standard.

    For reasons of common senseā€”and, as the note points out, this has nothing to do with markup minimizationā€”when an element is declared to be empty then the end-tag must be omitted.
    ā€¦
    If an element has a declared content of ā€œEMPTYā€, or an explicit content reference, the end-tag must be omitted.

    The SGML Handbook
    7.3 Element

    Also for reasons of common sense, end-tags that ā€œmust be omittedā€ cannot possibly be ā€œoptional tagsā€.

    The ā€œOā€ may serve a different purpose in empty element declarations:

    Recall that the end-tag must always be omitted if an element has empty content, because anything that follows the start-tag must then be part of the containing element. Although this rule has nothing to do with markup
    minimization, it is helpful to mark the ā€œOā€ as a reminder that no end-tags will be found in the document.

    The SGML Handbook
    C.1.2.3 End-tag Omission: Intruding Start-tag

    I.e. </area>, </img>, </input>etc. are not an optional tags in HTML 4 rather they are non-existent tags in HTML 4.

  16. On August 26, 2009, 14:00 CEST, Thomas HĆ¼hn said:

    Donā€™t expect OpenID discovery to work when omitting the HEAD start tag.

    Most implementations seem not to work under that circumstance. The widely used OpenID PHP library from openidenabled, for example.

  17. On August 24, 2010, 19:01 CEST, mozes66 said:

    1000 thanks.