HTML and CSS Reference
In-Depth Information
Well-formedness
According to well-formedness , a basic concept in XHTML, all elements must be closed and element nesting should be
done in the proper order (Listing 3-12). Overlapping elements are incorrect in XHTML (Listing 3-13).
Listing 3-12. Properly Nested Elements
<p> Part of this <strong> bold text should be <em> italic as well </em></strong> . </p>
Listing 3-13. Overlapping Elements (Incorrect)
<p>Part of this <strong>bold text should be <em>italic as well</strong></em>.</p>
Names Are in Lowercase
Since XML is case-sensitive, all XHTML element and attribute names must be in lowercase.
Required End Tags
In HTML, the end tag of several elements can be omitted, which is not allowed in XHTML (Listings 3-14 and 3-15).
Listing 3-14. Properly Closed Elements
<p>This is the first paragraph.</p>
<p>This is the second one.</p>
Listing 3-15. Unterminated Elements Are Incorrect in XHTML
<p>This is the first paragraph. <p>This is the second one.
All elements that are declared in the DTD as empty elements ( meta , link , br , hr , img , input ) can be closed either
by an end tag (similar to nonempty elements) or by the shorthand notation; in other words, a space and a slash
character are inserted prior to the end of the declaration, as shown in Listing 3-16.
Listing 3-16. Pseudocode of Element Closing with Shorthand Notation (Self-closing)
<element_name attrib1="value 1 " ... attribn="value n " />
which provides shorter code. Although the space before the slash is optional, it is preferred because the result is easier
to read (Listing 3-17). Tags without a closing tag are also known as self-closing tags .
Listing 3-17. Terminated Empty Element
<br / >
In XHTML, all unterminated elements are incorrect, including unterminated empty elements (Listing 3-18).
Listing 3-18. Unterminated Empty Elements Are Incorrect in XHTML
<br> unterminated elements are incorrect in XHTML <hr>
The script element applies either to the full form (with the end tag) or to the shorthand notation, depending on
the number of parameters and the behavior of the element.
 
Search WWH ::




Custom Search