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

HTML as an Application of SGML

HTML is an application of ISO 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.

In the SGML specification, the first production of the SGML syntax 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:

<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<title>Parsing Example</title>
<p>Some text. <em>&#42;wow&#42;</em></p>

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

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

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

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). The terminals above parse as:

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

Some of the elements are delimited explicitly by tags, while the boundaries of others are inferred. The HTML element contains a HEAD element and a BODY element. The HEAD contains TITLE, which is explicitly delimited by start- and end-tags.

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 repertoire of [ISO-646]. Data characters are drawn from the document character set (see section Characters, Words, and Paragraphs).

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 map to single-character strings, via the document character set. Each reference to one of the general entities defined in the HTML DTD maps to a single-character string.

For example,

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

The terminating semicolon on entity or numeric character references is only necessary when the character following the reference would otherwise be recognized as part of the name (see 9.4.5 "Reference End" in [SGML]).

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

An ampersand is only recognized as markup when it is followed by a letter or a `#' and a 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
       CHARACTER REFERENCE   CHAR REF     CHARACTER DESCRIPTION
       --------- ----------  -----------  ---------------------
         &       &amp;       &#38;        Ampersand 
         <       &lt;        &#60;        Less than
         >       &gt;        &#62;        Greater than

(5)

Tags

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, 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)

Names

A name consists of a letter followed by letters, digits, periods, or hyphens. The length of a name is limited to 72 characters by the `NAMELEN' parameter in the SGML declaration for HTML, section SGML Declaration for HTML. Element and attribute 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 `<'.

Attributes

In a start-tag, white space and attributes are allowed between the element name and the closing delimiter. An attribute specification typically consists of an attribute name, an equal sign, and a value, though some attribute specifications may be just a name token. 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 white space character by an entity reference or numeric character reference as follows:

                 ENTITY      NUMERIC
       CHARACTER REFERENCE   CHAR REF     CHARACTER DESCRIPTION
       --------- ----------  -----------  ---------------------
         HT                  &#9;         Tab
         LF                  &#10;        Line Feed
         CR                  &#13;        Carriage Return
         SP                  &#32;        Space
         "       &quot;      &#34;        Quotation mark 
         &       &amp;       &#38;        Ampersand 

For example:

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

The `NAMELEN' parameter in the SGML declaration (section SGML Declaration for HTML) limits the length of an attribute value to 1024 characters.

Attributes such as ISMAP and COMPACT may be written using a minimized syntax (see 7.9.1.2 "Omitted Attribute Name" in [SGML]). The markup:

<UL COMPACT="compact">

can be written using a minimized syntax:

<UL COMPACT>

(9)

Comments

To include comments in an HTML document, use a comment declaration. A comment declaration consists of `<!' followed by zero or more comments followed by `>'. Each comment starts with `--' and includes all text up to and including the next occurrence of `--'. In a comment declaration, white space is allowed after each comment, but not before the first comment. The entire comment declaration is ignored. (10)

For example:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HEAD>
<TITLE>HTML Comment Example</TITLE>
<!-- Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp  -->
<!-- another -- -- comment -->
<!>
</HEAD>
<BODY>
<p> <!- not a comment, just regular old data characters ->

HTML Public Text Identifiers

To identify information as an HTML document conforming to this specification, each document must start with one of the following document type declarations.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

This document type declaration refers to the HTML DTD in section HTML DTD. (11)

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Level 2//EN">

This document type declaration also refers to the HTML DTD which appears in section HTML DTD.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Level 1//EN">

This document type declaration refers to the level 1 HTML DTD in section Level 1 HTML DTD. Form elements must not occur in level 1 documents.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Strict//EN">
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Strict Level 1//EN">

These two document type declarations refer to the HTML DTD in section Strict HTML DTD and section Strict Level 1 HTML DTD. They refer to the more structurally rigid definition of HTML.

HTML user agents may support other document types. In particular, they may support other formal public identifiers, or other document types altogether. They may support an internal declaration subset with supplemental entity, element, and other markup declarations.

Example HTML Document

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<!-- Here's a good place to put a comment. -->
<HEAD>
<TITLE>Structural Example</TITLE>
</HEAD><BODY>
<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>
<OL>
<LI>First item in an ordered list.
<LI>Second item in an ordered list.
  <UL COMPACT>
  <LI> Note that lists can be nested;
  <LI> Whitespace may be used to assist in reading the 
       HTML source.
  </UL>
<LI>Third item in an ordered list.
</OL>
<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.
<P>
<IMG SRC ="triangle.xbm" alt="Warning: ">
Be sure to read these <b>bold instructions</b>.
</BODY></HTML>

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