Well-formed element

In web page design, and generally for all markup languages such as SGML, HTML, and XML, a well-formed element is one that is either

For example, in HTML: <b>word</b> is a well-formed element, while <i><b>word</i> is not, since the bold element is not closed. In XHTML, empty elements (elements that inherently have no content) should be closed by putting a slash at the end of the opening tag, e.g. <img />, <br />, <hr />, etc. In HTML, there is no closing tag for such elements, and no slash is added to the opening tag.

In a well-formed document,

For example, the code below is not well-formed HTML, because the em and strong elements overlap:

<!-- WRONG! NOT WELL-FORMED HTML! -->
<p>Normal <em>emphasized <strong>strong emphasized</em> strong</strong></p>

<!-- Correct: Well-formed HTML. -->
<p>Normal <em>emphasized <strong>strong emphasized</strong></em> <strong>strong</strong></p>
<p>Alternatively <em>emphasized</em> <strong><em>strong emphasized</em> strong</strong></p>

In XML, the phrase well-formed document is often used to describe a text that follows all the syntactic rules labelled 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).


This article is issued from Wikipedia - version of the 5/15/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.