HTML element
An HTML element is a type of HTML document component, one of several types of HTML nodes. The first used version of HTML was written by Tim Berners-Lee in 1993 and there have since been many versions of HTML. The current de facto standard is governed by the industry group WHATWG and is known as the HTML Living Standard.
An HTML document is composed of a tree of simple HTML nodes, such as text nodes, and HTML elements, which add semantics and formatting to parts of a document. Each element can have HTML attributes specified. Elements can also have content, including other elements and text.
Concepts
Elements vs. tags
As is generally understood, the position of an element is indicated as spanning from a start tag and is terminated by an end tag. This is the case for many, but not all, elements within an HTML document. The distinction is explicitly emphasised in HTML 4.01 Specification:Similarly the W3C Recommendation HTML 5.1 2nd Edition explicitly says:
and:
As HTML is based on SGML, its parsing also depends on the Document Type Definition, specifically an HTML DTD. The DTD specifies which element types are possible and also the valid combinations in which they may appear in a document. It is part of general SGML behavior that, where only one valid structure is , its explicit statement in any given document is not generally required. As a simple example, the tag indicating the start of a paragraph element should be complemented by a tag indicating its end. But since the DTD states that paragraph elements cannot be nested, an HTML document fragment is thus inferred to be equivalent to. Because this implication is based on the combination of the DTD and the individual document, it is not usually possible to infer elements from document tags but only by using an SGML—or HTML—aware parser with knowledge of the DTD. HTML5 creates a similar result by defining what tags can be omitted.
SGML vs. XML
SGML is complex, which has limited its widespread understanding and adoption. XML was developed as a simpler alternative. Although both can use the DTD to specify the supported elements and their permitted combinations as document structure, XML parsing is simpler. The relation from tags to elements is always that of parsing the actual tags included in the document, without the implied closures that are part of SGML.HTML as used on the current web is likely to be either treated as XML, by being XHTML, or as HTML5; in either case the parsing of document tags into Document Object Model elements is simplified compared to legacy HTML systems. Once the DOM of elements is obtained, behavior at higher levels of interface is identical or nearly so.
%block; vs. box
Part of this CSS presentation behavior is the notion of the "box model". This is applied to those elements that CSS considers to be "block" elements, set through the CSS declaration.HTML also has a similar concept, although different, and the two are very frequently confused.
%block; and %inline; are groups within the HTML DTD that group elements as being either "block-level" or "inline". This is used to define their nesting behavior: block-level elements cannot be placed into an inline context. This behavior cannot be changed; it is fixed in the DTD. Block and inline elements have the appropriate and different CSS behaviors attached to them by default, including the relevance of the box model for particular element types.Note though that this CSS behavior can, and frequently is, changed from the default. Lists with are
%block; elements and are presented as block elements by default. However, it is quite common to set these with CSS to display as an inline list.Overview
Syntax
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, to distinguish it from the start tag. 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. Some elements, the so-called [|void elements], do not have an end tag. A typical example is the element. A void element's behavior is predefined, and it cannot contain any content or other elements. For example, an address would be written as:
P. Sherman
42 Wallaby Way
Sydney
When using XHTML, it is required to open and close all elements, including void elements. This can be done by placing an end tag immediately after the start tag, but this is not legal in HTML 5 and will lead to two elements being created. An alternative way to specify that it is a void element, which is compatible with both XHTML and HTML 5, is to put a
/ at the of the tag.P. Sherman
42 Wallaby Way
Sydney
HTML attributes are specified inside the start tag. For example, the element, which represents an abbreviation, expects a
title attribute within its opening tag. This would be written as:abbr.
Informally, HTML elements are sometimes referred to as "tags", though many prefer the term tag strictly in reference to the markup delimiting the start and end of an element.
Element names may be written in any combination of upper or lower case in HTML, but must be in lower case in XHTML. 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:.
- a start tag marking the beginning of an element, which may incorporate any number of HTML attributes;
- some amount of text content, but no elements ;
- 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.
only have a start tag, 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. The slash is required in XHTML and other XML applications. Two common void elements are and . 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, 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. 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 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 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 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. 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.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 form of HTML.
The first Standard 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.
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.