In
web page design, and generally for all
markup language
A markup language is a Encoding, text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts. Markup can control the display of a document or enrich its content to facilitate au ...
s such as
SGML
The Standard Generalized Markup Language (SGML; International Organization for Standardization, ISO 8879:1986) is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on t ...
,
HTML
Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
, and
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
, a well-formed element is one that is either a) opened and subsequently closed, or b) an empty element, which in that case must be terminated; and in either case which is properly
nested so that it does not
overlap
Overlap may refer to:
* In set theory, an overlap of elements shared between sets is called an intersection, as in a Venn diagram.
* In music theory, overlap is a synonym for reinterpretation of a chord at the boundary of two musical phrases
* Ove ...
with other elements.
For example, in HTML:
word
is a well-formed element, while is not, since the bold element is not closed.
In
XHTML
Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages which mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.
While HTML, pr ...
, and XML, empty elements (elements that inherently have no content) are terminated by putting a slash at the end of the "opening" (only) tag, e.g. etc. In HTML 4.01 and earlier, no slash is added to terminate the element.
HTML5
HTML5 (Hypertext Markup Language 5) is a markup language used for structuring and presenting hypertext documents on the World Wide Web. It was the fifth and final major HTML version that is now a retired World Wide Web Consortium (W3C) recommend ...
does not require one, but it is often added for compatibility with XHTML and XML processing.
In a well-formed document,
* all elements are well-formed, and
* a single element, known as the
root element, contains all of the other elements in the document.
For example, the code below is not well-formed HTML, because the
em
and
strong
Strong may refer to:
Education
* The Strong, an educational institution in Rochester, New York, United States
* Strong Hall (Lawrence, Kansas), an administrative hall of the University of Kansas
* Strong School, New Haven, Connecticut, United ...
elements overlap:
Normal emphasized strong emphasized strong
Normal emphasized strong emphasized strong
Alternatively emphasized strong emphasized strong
In
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
, the phrase ''
well-formed document'' is often used to describe a text that follows all the syntactic rules as well-formedness rules in the XML specification: strictly speaking the phrase is tautological, since a text that does not follow these rules is not an XML document. The rules for well-formed XML documents go beyond the general requirements for the markup languages mentioned above. The additional rules include, for example, a rule to quote attribute values,
case-sensitiveness of tag names, rules about the characters that can appear in names and elsewhere, the syntax of comments,
processing instructions, entity references, and CDATA sections, and many other similar details. Sometimes the adjective well-formed is used to contrast with valid: a valid XML document is one that is not only well-formed, but also conforms to the grammar defined in its own DTD (
Document Type Definition).
XML
HTML
{{Web-stub