Appendix A. HTML Grammar
For the most part, browsers do not rigidly enforce the exact syntax of an HTML or even an XHTML document. This gives authors wide latitude in creating documents and gives rise to documents that work on most browsers but actually are incompatible with the HTML and XHTML standards. Our advice is to stick to the standards, unless your documents are fly-by-night affairs.
The standards explicitly define the ordering and nesting of tags and document elements. This syntax is embedded within the appropriate Document Type Definition (DTD) and is not readily understood by those who are not versed in Standard Generalized Markup Language (SGML; for the HTML 4.01 DTD, see Appendix D) or Extensible Markup Language (XML; for the XHTML 1.0 DTD, see Appendix E). Accordingly, we provide an alternate definition of the allowable HTML and XHTML syntax, using a fairly common tool called a grammar.
Grammar, whether it defines English sentences or HTML documents, is just a set of rules that indicates the order of language elements. These language elements can be divided into two sets: terminal (the actual words of the language) and nonterminal (all other grammatical rules). In HTML and XHTML, the words correspond to the embedded markup tags and text in a document.
To use the grammar to create a valid document, follow the order of the rules to see where the tags and text may be placed to create a valid document.
Grammatical Conventions
We use a number of typographic and punctuation ...
Get HTML & XHTML: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.