Syntax {{Image frame|caption=Parts of an HTML container element \overbrace{ \overbrace{\mathtt{\color{BrickRed}}}^\mathsf{Start\ tag} \overbrace\mathtt{\color{Green}This\ is\ a\ paragraph.}^\mathsf{Content} \overbrace\mathtt{\color{BrickRed}}^\mathsf{End \atop tag} }^\mathsf{Element} }} In the HTML
syntax, most elements are written with a start tag and an end tag, with the content in between. An HTML tag is composed of the name of the element, surrounded by
angle brackets. An end tag also has a slash after the opening angle bracket. For example, a paragraph, which is represented by the element, would be written as: In the HTML syntax, most elements are written ... However, not all of these elements the end tag, or even the start tag, to be present. The canonical form was upper-case until
HTML 4, and was used in HTML specifications, but in recent years, lower-case has become more common.
Types of element There are three kinds of
HTML elements: normal elements, raw text elements, and void elements. '''''' usually have both a start tag and an end tag, although for some elements the end tag, or both tags, can be omitted. It is constructed in a similar way: • a
start tag () marking the beginning of an element, which may incorporate any number of
HTML attributes; • some amount of
content, including text and other elements; • an
end tag, in which the element name is prefixed with a
slash: . '''''' (also known as text or text-only elements) are constructed with: • a
start tag (in the form ) marking the beginning of an element, which may incorporate any number of HTML attributes; • some amount of text
content, but no elements (all tags, apart from the applicable end tag, will be interpreted as content); • an
end tag, in which the element name is prefixed with a slash: . In some versions of HTML, the end tag is optional for some elements. The end tag is required in XHTML. An example is the element, which must not contain other elements (including markup of text), only text. '''''' (also sometimes called empty elements, single elements or stand-alone elements) only have a start tag (in the form ), which contains any HTML attributes. They may not contain any children, such as text or other elements. For compatibility with
XHTML, the HTML specification allows an optional space and slash ( is permissible). The slash is required in
XHTML and other
XML applications. Two common void elements are (for a
hard line-break, such as in a poem or an address) and (for a
thematic break). Other such elements are often place-holders which reference external files, such as the image () element. The attributes included in the element will then point to the external file in question. Another example of a void element is , for which the syntax is: This element points the browser at a
style sheet to use when presenting the HTML document to the user. In the HTML syntax attributes do not have to be quoted if they are composed only of certain characters: letters, digits, the hyphen-minus and the period. When using the XML syntax (XHTML), on the other hand, all attributes must be quoted, and a spaced trailing
slash is required before the last angle bracket:
Attributes HTML attributes define desired behavior or indicate additional element properties. Most attributes require a
value. In HTML, the value can be left unquoted if it does not include spaces (=), or it can be quoted with single or double quotes (='' or =""). In
XML, those quotes are required.
Boolean attributes, on the other hand, do not require a value to be specified. An example is the checked for checkboxes: In the XML (and thus
XHTML) syntax, though, a value is required, and the name should be repeated as the value:
Element standards HTML elements are defined in a series of freely available open standards issued since 1995, initially by the
IETF and subsequently by the
W3C. During the
browser wars of the 1990s, developers of
user agents (e.g.
web browsers) often developed their own elements, some of which have been adopted in later standards. Other user agents may not recognize non-standard elements, and they will be ignored, possibly causing the page to be displayed improperly. In 1998,
XML (a simplified form of SGML) introduced mechanisms to allow anyone to develop their own elements and incorporate them in
XHTML documents, for use with XML-aware user agents. Subsequently, HTML 4.01 was rewritten in an
XML-compatible form,
XHTML 1.0 (
eXtensible HTML). The elements in each are identical, and in most cases valid XHTML 1.0 documents will be valid or nearly valid HTML 4.01 documents. This article mainly focuses on real HTML, unless noted otherwise; however, it remains applicable to XHTML. See
HTML for a discussion of the minor differences between the two.
Element status Since the first version of HTML, several elements have become outmoded, and are
deprecated in later standards, or do not appear at all, in which case they are
invalid (and will be found invalid, and perhaps not displayed, by
validating user agents). In
HTML 4.01 /
XHTML 1.0, the status of elements is complicated by the existence of three types of
DTD: •
Transitional, which contain deprecated elements, but which were intended to provide a transitional period during which authors could update their practices; •
Frameset, which are versions of the Transitional DTDs which also allow authors to write
frameset documents; •
Strict, which is the up-to-date (as at 1999) form of HTML. HTML5 instead provides a listing of
obsolete features to go along with the
standardized normative content. They are broken down into "obsolete but conforming" for which implementation instructions exist and "non-conforming" ones that should be replaced. The first Standard (
HTML 2.0) contained four deprecated elements, one of which was invalid in
HTML 3.2. All four are invalid in
HTML 4.01 Transitional, which also deprecated a further ten elements. All of these, plus two others, are invalid in
HTML 4.01 Strict. While the frame elements are still current in the sense of being present in the Transitional and Frameset DTDs, there are no plans to preserve them in future standards, as their function has been largely replaced, and they are highly problematic for user accessibility. (Strictly speaking, the most recent
XHTML standard,
XHTML 1.1 (2001), does not include frames at all; it is approximately equivalent to
XHTML 1.0 Strict, but also includes the
Ruby markup module.) A common source of confusion is the loose use of
deprecated to refer to both deprecated and invalid status, and to elements that are expected to be formally deprecated in the future.
Content vs. presentation and behavior Since HTML 4, HTML has increasingly focused on the separation of content (the visible text and images) from presentation (like color, font size, and layout). This is often referred to as a
separation of concerns. HTML is used to represent the structure or content of a document, its presentation remains the sole responsibility of
CSS style sheets. A default
style sheet is suggested as part of the CSS standard, giving a default rendering for HTML. Behavior (interactivity) is also kept separate from content, and is handled by
scripts. Images are contained in separate
graphics files, separate from text, though they can also be considered part of the content of a page. Separation of concerns allows the document to be presented by different user agents according to their purposes and abilities. For example, a user agent can select an appropriate style sheet to present a document by displaying on a monitor, printing on paper, or to determine speech characteristics in an audio-only user agent. The structural and semantic functions of the markup remain identical in each case. Historically, user agents did not always support these features. In the 1990s, as a stop-gap, presentational elements (like and ) were added to HTML, at the cost of creating problems for interoperability and user accessibility. This is now regarded as outmoded and has been superseded by style sheet-based design; most presentational elements are now deprecated. External image files are incorporated with the or elements. (With
XHTML, the
SVG language can also be used to write graphics within the document, though linking to external SVG files is generally simpler.) Where an image is not purely decorative, HTML allows replacement content with similar semantic value to be provided for non-visual user agents. An HTML document can also be extended through the use of scripts to provide additional behaviors beyond the abilities of HTML hyperlinks and forms. The elements and , with related
HTML attributes, provide style sheets and scripts. • In the document head, and may link to shared external documents, or and may contain embedded instructions. (The element can also be used to link style sheets.) • or can occur at any point in the document (head or body). • The style attribute is valid in most document body elements (e.g. ) for inclusion of
inline style instructions. •
Event-handling attributes, which provide links to scripts, are optional in most elements. • For user agents which do not operate scripts, the element provides embedded alternative content where appropriate; however, it can only be used in the document head and in the body as a block-level element. ==Document structure elements==