Character Entities

 <  Day Day Up  >  


After covering most of the block elements and the basic inline text formatting elements, you might think that nothing remains to talk about ”but there is one more level to HTML and XHTML documents: the characters themselves .

Sometimes, you need to put special characters within a document, such as accented letters , copyright symbols, or even the angle brackets used to enclose HTML elements. To use such characters in an HTML document, they must be "escaped" by using a special code. All character codes take the form & code; , in which code is a word or numeric code indicating the actual character that you want to put onscreen. Some of the more commonly used characters are shown in Table 3-3.

Table 3-3: Commonly Used Character Entities

Numeric Value

Named Value

Symbol

Description

&#034;

&quot;

Quotation mark

&#038;

&amp;

&

Ampersand

&#060;

&lt;

<

Less than

&#062;

&gt;

>

Greater than

&#153;

&trade;

¢

Trademark

&#160;

&nbsp;

 

Non-breaking space

&#169;

&copy;

Copyright symbol

&#174;

&reg;

Registered trademark

Note  

The character entity &#153; might not always be acceptable as trademark. On many UNIX platforms, and potentially on Macs or Windows systems using various "other" character sets, this entity doesn't render as trademark. &153; can be undefined and you may even find trouble with the &trade; named entity. However, trademarks are important legally, so they often are needed. The commonly used workaround is < sup><small> TM </small></sup> . This markup creates a superscript trademark symbol (¢) in a slightly smaller font. Because it's standard HTML, it works on nearly every platform.

The following example shows some basic uses of HTML character entities. Figure 3-15 shows how the example might render.

click to expand
Figure 3-15: Rendering of character entities example
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml" lang="en">   <head>   <title>  Character Entity Example  </title>   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />   </head>   <body>   <h1 align="center">  Character Entities Demo  </h1>   <hr />   <p>  Character entities like  &amp;  copy  ;  allow users to insert special characters like  &copy;  .  </p>   <p>  One entity that is both useful and abused is the non-breaking space.  </p>   <p>  Inserting spaces is easy with  &amp;  nbsp;  <br />  Look:  &nbsp;  S  &nbsp; &nbsp; &nbsp;  P  &nbsp; &nbsp; &nbsp;  A  &nbsp; &nbsp; &nbsp;  C  &nbsp; &nbsp; &nbsp;  E  &nbsp; &nbsp; &nbsp;  S.  <br />   </p>   <hr />   <address>  Contents of this page  &copy; 2003  Demo Company, Inc.  <br />  The  <strong>  Wonder Tag  </strong> &lt;  P  &gt; &#153;  is a registered  trademark of Demo Company, Inc.  </address>   </body>   </html>  
Note  

The use of the nonbreaking space to push text or elements around the screen is an overused crutch. Many HTML editors overuse this technique in an attempt to preserve look and feel.

While entities are easy to add, excessive use can make markup difficult to read, particularly if the character entities aren't well spaced .

The character set currently supported by HTML is the ISO Latin-1 character set. Many of its characters, such as accents and special symbols, cannot be typed on all keyboards. They must be entered into HTML documents by using the appropriate code. Even if the character in question is supported on the keyboard (for example, the copyright symbol), simply typing the symbol into the document directly may not produce the correct encoding. Of course, many HTML editors make the appropriate insertion for you. A complete list of the character entities is presented in Appendix C.

Note  

HTML is capable of representing the standard ASCII characters and all the extended characters defined by the ISO Latin-1 character set. However, for non-Western characters, such as Japanese, Russian, or Arabic alphabets, special encoding extensions to a browser or operating system may be required.



 <  Day Day Up  >  


HTML & XHTML
HTML & XHTML: The Complete Reference (Osborne Complete Reference Series)
ISBN: 007222942X
EAN: 2147483647
Year: 2003
Pages: 252
Authors: Thomas Powell

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