Character Entities
XHTML (as a function of XML) is extremely fussy about special characters such as <
, >
, and &
. All special characters should be represented in the XHTML document by their character entities instead. Common character entities are listed in Table 10-3, and the complete list appears in Appendix C.
Character entity references should be used in place of characters such as <
and &
in regular text content, as shown in these examples:
<p> the value of A < B </p> <p> Laverne & Shirley </p>
In places where it was common to use special characters, such as in the title of a document or in an attribute value, it is now necessary to use the character entity instead. For instance, the following worked just fine in HTML, despite being invalid:
<img src="puppets.jpg" alt="Crocco & Lynch">
But in XHTML, the value must be written like this:
<img src="puppets.jpg" alt="Crocco & Lynch" />
This applies to ampersands that occur in URLs as well.
<a href="mailto: jen@example.com ? subject=subject&cc=person "> Email Jen<a/>
Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.