Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Well-formed element
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Markup language element which is correctly nested and tagged}} {{Unreferenced|date=December 2009}} In [[web page design]], and generally for all [[markup language]]s such as [[SGML]], [[HTML]], and [[XML]], 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 [[Nesting (computing)|nested]] so that it does not [[Overlapping markup|overlap]] with other elements. For example, in HTML: <code><nowiki><b>word</b></nowiki></code> is a well-formed element, while {{nowrap|<code><nowiki><i><b>word</i></nowiki></code>}} is not, since the bold element {{tag|b|open}} is not closed. In [[XHTML]], 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. {{nowrap|{{tag|img|s}},}} {{nowrap|{{tag|br|s}},}} {{nowrap|{{tag|hr|s}},}} etc. In HTML 4.01 and earlier, no slash is added to terminate the element. [[HTML5]] 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 <code>[[Html element#General phrase elements|em]]</code> and <code>[[Html element#General phrase elements|strong]]</code> elements overlap: <syntaxhighlight lang="xml"> <!-- WRONG! NOT well-formed HTML! --> <p>Normal <em>emphasized <strong>strong emphasized</em> strong</strong></p> </syntaxhighlight> <syntaxhighlight lang="xml"> <!-- 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> </syntaxhighlight> In [[XML]], 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 sensitive|case-sensitiveness]] of tag names, rules about the characters that can appear in names and elsewhere, the syntax of comments, [[processing instruction]]s, 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]]). [[Category:XML]] [[Category:HTML]] {{Web-stub}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)