Go to the first, previous, next, last section, table of contents.

HTML as an Application of SGML

HTML is an application of ISO Standard 8879:1986 - Standard Generalized Markup Language (SGML). SGML is a system for defining structured document types and markup languages to represent instances of those document types[SGML]. The public text -- DTD and SGML declaration -- of the HTML document type definition are provided in section HTML Public Text.

The term HTML refers to both the document type defined here and the markup language for representing instances of this document type.

SGML Documents

An HTML document is an SGML document; that is, a sequence of characters organized physically into a set of entities, and logically as a hierarchy of elements.

The first production of the SGML grammar separates an SGML document into three parts: an SGML declaration, a prologue, and an instance. For the purposes of this specification, the prologue is a DTD. This DTD describes another grammar: the start symbol is given in the doctype declaration; the terminals are data characters and tags, and the productions are determined by the element declarations. The instance must conform to the DTD, that is, it must be in the language defined by this grammar.

The SGML declaration determines the lexicon of the grammar. It specifies the document character set, which determines a character repertoire that contains all characters that occur in all text entities in the document, and the code positions associated with those characters.

The SGML declaration also specifies the syntax-reference character set of the document, and a few other parameters that bind the abstract syntax of SGML to a concrete syntax. This concrete syntax determines how the sequence of characters of the document is mapped to a sequence of terminals in the grammar of the prologue.

For example, consider the following document:

<title>Parsing Example</title>
<p>Some text. <em>&#42;wow&#42;</em></p>

An HTML user agent should use the SGML declaration is given in section SGML Declaration for HTML. According to the document character set there,`&#42;' refers to an asterisk character.

The instance above is regarded as the following sequence of terminals:

  1. TITLE start-tag
  2. data characters: "Parsing Example"
  3. TITLE end-tag
  4. P start-tag
  5. data characters "Some text. "
  6. EM start-tag
  7. "*wow*"
  8. EM end-tag

The start symbol of the DTD grammar is HTML, and the productions are given in the public text identified by `-//IETF//DTD HTML 2.0//EN' (section HTML DTD). Hence the terminals above parse as:

    |  |
    |  \-TITLE
    |      |
    |      \-<TITLE>
    |      |
    |      \-"Parsing Example"
    |      |
    |      \-</TITLE>
        \-"Some text. "
        |  |
        |  \-<EM>
        |  |
        |  \-"*wow*"
        |  |
        |  \-</EM>

HTML Lexical Syntax

SGML specifies an abstract syntax and a reference concrete syntax. Aside from certain quantities and capacities (e.g. the limit on the length of a name), all HTML documents use the reference concrete syntax. In particular, all markup characters are in the ISO-646-IRV character repertoire. Data characters are drawn from the document character set (see section Character Content).

A complete discussion of SGML parsing, e.g. the mapping of a sequence of characters to a sequence of tags and data is left to the SGML standard[SGML]. This section is only a summary.

Data Characters

Any sequence of characters that do not constitute markup (see 9.6 "Delimiter Recognition" of [SGML]) are mapped directly to strings of data characters. Some markup also maps to data character strings. Numeric character references also map to single-character strings, via the document character set. Each reference to one of the general entities defined in the HTML DTD also maps to a single-character string.

For example,

abc&lt;def    => "abc","<","def"
abc&#60;def   => "abc","<","def"

Note that the terminating semicolon is only necessary when the character following the reference would otherwise be recognized as markup:

abc &lt def     => "abc ","<"," def"
abc &#60 def    => "abc ","<"," def"

And note that an ampersand is only recognized as markup when it is followed by a letter or digit:

abc & lt def    => "abc & lt def"
abc & 60 def    => "abc & 60 def"

A useful technique for translating plain text to HTML is to replace each '<', '&', and '>' by an entity reference or numeric character reference as follows:

                 ENTITY      NUMERIC
         &       &amp;       &#38;        Ampersand 
         <       &lt;        &#60;        Less than
         >       &gt;        &#62;        Greater than



Tags delimit elements such as headings, paragraphs, lists, character highlighting and links. Most HTML elements are identified in a document as a start-tag, which gives the element name and attributes, followed by the content, followed by the end tag. Start-tags are delimited by `<' and `>'; end tags are delimited by `</' and `>'. An example is:

<H1>This is a Heading</H1>

Some elements only have a start-tag without an end-tag. For example, to create a line break, you use the `<BR>' tag. Additionally, the end tags of some other elements, such as Paragraph (`</P>'), List Item (`</LI>'), Definition Term (`</DT>'), and Definition Description (`<DD>') elements, may be omitted.

The content of an element is a sequence of data character strings and nested elements. Some elements, such as anchors, cannot be nested. Anchors and character highlighting may be put inside other constructs. See the HTML DTD, section HTML DTD for full details. (6)


A name consists of a letter followed by up to 71 letters, digits, periods, or hyphens. Element names are not case sensitive, but entity names are. For example, `<BLOCKQUOTE>', `<BlockQuote>', and `<blockquote>' are equivalent, whereas `&amp;' is different from `&AMP;'.

In a start-tag, the element name must immediately follow the tag open delimiter `<'.


In a start-tag, white space and attributes are allowed between the element name and the closing delimiter. An attribute typically consists of an attribute name, an equal sign, and a value, though some attributes may be just a value. White space is allowed around the equal sign.

The value of the attribute may be either:

In this example, img is the element name, `src' is the attribute name, and `http://host/dir/file.gif' is the attribute value:

<img src="http://host/dir/file.gif">


A useful technique for computing an attribute value literal for a given string is to replace each quote and space character by an entity reference or numeric character reference as follows:

                 ENTITY      NUMERIC
         TAB                 &#9;         Tab
         LF                  &#10;        Line Feed
         CR                  &#13;        Carriage Return
                             &#32;        Space
         "       &quot;      &#34;        Quotation mark 
         &       &amp;       &#38;        Ampersand 

For example:

<IMG SRC="image.jpg" alt="First &quot;real&quot; example">


Note that the SGML declaration in section 13.3 limits the length of an attribute value to 1024 characters.

Attributes such as ISMAP and COMPACT, may be written using a minimized syntax. The markup:

<UL COMPACT="compact">

can be written using a minimized syntax:




To include comments in an HTML document that will be eliminated in the mapping to terminals, surround them with `<!--' and `-->'. After the comment delimiter, all text up to the next occurrence of `-->' is ignored. Hence comments cannot be nested. White space is allowed between the closing `--' and `>', but not between the opening `<!' and `--'.

For example:

<TITLE>HTML Guide: Recommended Usage</TITLE>
<!-- $Id: html-sgml.sgm,v 1.4 1995/05/06 01:44:46 connolly Exp $ -->


Example HTML Document

<!-- Here's a good place to put a comment. -->
<TITLE>Structural Example</TITLE>
<H1>First Header</H1>
<P>This is a paragraph in the example HTML file. Keep in mind 
that the title does not appear in the document text, but that 
the header (defined by H1) does.</P>
<LI>First item in an ordered list.
<LI>Second item in an ordered list.
  <LI> Note that lists can be nested;
  <LI> Whitespace may be used to assist in reading the 
       HTML source.
<LI>Third item in an ordered list.
<P>This is an additional paragraph. Technically, end tags are 
not required for paragraphs, although they are allowed. You can 
include character highlighting in a paragraph. <EM>This sentence 
of the paragraph is emphasized.</EM> Note that the &lt;/P&gt; 
end tag has been omitted.
<IMG SRC ="triangle.xbm" alt="Warning: ">
Be sure to read these <b>bold instructions</b>.

Go to the first, previous, next, last section, table of contents.