Character Entities

A character entity is simply a code that represents a character. Every character that can be displayed on the screen has a corresponding character entity. Character entities are useful when you want to display a character that would normally present display or entry difficulties. For example, suppose you want to display a less-than symbol (<) in the browser. This symbol is normally used to signify the beginning of an HTML tag and, if simply keyed in as text, could confuse the browser. Instead, you can use a character entity to represent the symbol and avoid potential problems. This concept is demonstrated in Code Listing 4-10 and displayed in Figure 4-10.

Code Listing 4-10.

<HTML> <HEAD> <TITLE>Listing 4-10</TITLE> </HEAD> <BODY> Display in bold that X is less than Y: <B> X&lt;Y </B>. This paragraph uses a character entity. <HR> Display in bold that X is less than Y: <B> X<Y </B>. This paragraph does not use a character entity.  </BODY> </HTML> 

click to view at full size.

Figure 4-10. Character entities display as their corresponding characters.

The first sample uses the character entity for the less-than symbol (&lt;) and, as a result, everything displays as expected. The second sample uses the less-than character itself. In this instance, everything between the less-than character and the end of the closing boldface tag is treated as though it is inside an HTML tag and is not displayed. Additionally, the closing boldface tag is no longer parsed properly; thus, the rest of the text on the page displays in boldface.

A character entity is composed of three parts. The first is the ampersand symbol (&). This lets the browser know that a character entity begins here. Next comes either a number, prefaced with a number sign (#), or a name that identifies the specific entity. All entities have numerical identifiers, while some frequently used entities have been given names and are known as named entities. The less-than entity shown previously is a good example. It can be identified with either #60 or lt. The last part of the character entity is the semicolon (;). This signifies the end of the entity to the browser. A list of many common entities can be found in Appendix D. Table 4-1, on the following page, lists some of the most commonly used character entities.

NOTE
The numerical values for character entities are derived from the Unicode version 2.0 (more specifically, the ISO standard ISO10646) character set, a table of tens of thousands of characters from all over the world.

In the next chapter, we will investigate the Document Object Model. This tool for content developers goes beyond traditional HTML and allows an unprecedented level of control in Web page construction.

Table 4-1.

Displays As Numerical Identifier Named Entity Description Notes
&#09; Horizontal tab
&#13; Carriage return
&#32; Space
! &#33; Exclamation mark
" &#34; &quot; Quotation mark Can be useful in script
/ &#47; Solidus (slash)
< &#60; &lt; Less than Prevents the browser from interpreting < as the beginning of a tag
> &#62; &gt; Greater than
\ &#92; Reverse solidus (backslash)
... &#133; Ellipsis
&#153; Trademark
&#160; &nbsp; Nonbreaking space Useful for "nudging"(inserting a small amount of space) or to separate two words between which you do not want a line break
© &#169; &copy; Copyright
® &#174; &reg; Registered trademark
± &#177; &plusmn; Plus or minus
² &#178; &sup2; Superscript two
³ &#179; &sup3; Superscript three
¹ &#185; &sup1; Superscript one
¼ &#188; &frac14; Fraction one-fourth
½ &#189; &frac12; Fraction one-half
¾ &#190; &frac34; Fraction three-fourths
æ &#230; &aelig; Lowercase ae ligature



Dynamic HTML in Action
Dynamic HTML in Action
ISBN: 0735605637
EAN: 2147483647
Year: 1999
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net