Learning HTML 3.2 by Examples, section 3 General remarks on the syntax of HTML:

Classification of elements

The ways in which HTML tags can be combined are defined in terms of elements and their classification. It is much more convenient to define e.g. that an H1 element may contain (only) text elements than to give a long list of allowable elements, especially since the same list would appear in many contexts and it may change when new text elements are added to HTML in its future revisions.

Apart from the elements at the topmost levels, namely HTML, HEAD and BODY, the HTML elements are classified into three major categories:

Any text element (including plain text) can appear wherever a block element is allowed.

A rule of thumb which may help in remembering which elements are block elements and which are text elements: block elements cause paragraph breaks, text elements do not.

Note: Often block elements can contain both text elements and other block elements, i.e. blocks can be nested. Text elements can be nested, too. On the other hand, text elements may not contain block elements. For example,
<CITE><H3>Origin of Species</H3></CITE>
is invalid (since CITE is text element and H3 is block element) and also illogical (you don't really mean that the heading as a structure is a citation, do you?) whereas
<H3><CITE>Origin of Species</CITE></H3>
would be legal, although different browsers might treat it differently (letting either H3 or CITE determine the rendering, or possibly using a mixture of the two). Similarly, don't embed headings into A NAME tags but vice versa. It is also illegal to have a paragraph break (P tag) within e.g. a STRONG element; although several browsers can handle it, the semantics is ambiguous and you should use separate start and end STRONG tags within each paragraph (if you really want to emphasize such large portions of text!).


Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.