HTML and CSS Reference
In-Depth Information
Character Entities for Reserved Characters
For the most part, character entities exist so that you can include special characters that
aren't part of the standard ASCII character set. However, there are several exceptions for
the few characters that have special meaning in HTML itself. You must use entities for
these characters, too.
Suppose that you want to include a line of code that looks something like the following
in an HTML file:
<p><code> if x < 0 do print i </code></p>
Doesn't look unusual, does it? Unfortunately, HTML cannot display this line as written.
Why? The problem is with the < (less-than) character. To an HTML browser, the less-
than character means “this is the start of a tag.” Because the less-than character isn't
actually the start of a tag in this context, your browser might get confused. You'll have
the same problem with the greater-than character ( > ) because it means the end of a tag in
HTML, and with the ampersand ( & ) because it signals the beginning of an entity. Written
correctly for HTML, the preceding line of code would look like the following instead:
<p><code> if x &lt; 0 do print i </code></p>
HTML provides named entities for each of these characters, and one for the double quo-
tation mark, too, as shown in Table 7.1.
TABLE 7.1
Escape Codes for Characters Used by Tags
Entity
Result
&lt;
<
&gt;
>
&amp;
&
&quot;
The double quotation mark escape is the mysterious one. Technically, if you want to
include a double quotation mark in text, you should use the escape sequence, and you
shouldn't type the quotation mark character. However, I haven't noticed any browsers
having problems displaying the double quotation mark character when it's typed literally
in an HTML file, nor have I seen many HTML files that use it. For the most part, you're
probably safe using plain old quotes ( ) in your HTML files rather than the escape code.
Furthermore, HTML validators will not flag quotation marks that are not encoded using
entities.
 
 
Search WWH ::




Custom Search