Search code examples
htmldtdw3c

What does this HTML code (`<!ENTITY % html.content …>`, `<!ELEMENT …>`, `<!ATTLIST …>`) written at w3.org mean?


I was reading about the structure of an HTML document in the HTML 4.01 specification at w3.org. Then I stumbled upon this code; it looks like some kind of definition. Are any of you able to elaborate on what is it used for, and what it means?

<!ENTITY % html.content "HEAD, BODY">

<!ELEMENT HTML O O (%html.content;)    -- document root element -->
<!ATTLIST HTML
  %i18n;                               -- lang, dir --
>

Solution

  • It’s a fragment of one of the HTML 4.01 DTDs: the Document Type Definition.

    See the tag wiki for which contains further links.

    DTDs define formal grammars for XML documents: which tags you can use and where you can use them.

    The HTML 4.01 specification you’re reading has an introduction that provides an overview of how the spec is structured.

    1.1 How the specification is organized

    Sections 2 and 3: Introduction to HTML 4

    […]

    The brief SGML tutorial gives readers some understanding of HTML’s relationship to SGML and gives summary information on how to read the HTML Document Type Definition (DTD).

    The third section provides an in-depth explanation:

    3.3 How to read the HTML DTD

    Each element and attribute declaration in this specification is accompanied by its document type definition fragment. We have chosen to include the DTD fragments in the specification rather than seek a more approachable, but longer and less precise means of describing an element’s properties. The following tutorial should allow readers unfamiliar with SGML to read the DTD and understand the technical details of the HTML specification.