The Wayback Machine - https://web.archive.org/web/20081201132439/http://www.webreference.com/html/tutorial17/5.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 17 / 5

index12345summary

Tutorial 17: Shady Characters

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Character entity references

Character entity references allow you to use a simple, memorable name instead of a number to refer to a character. The upside of this approach is twofold: First of all, as humans, we are more likely to remember a name like "quot" instead of the number 34 (which is the number to use for a quotation mark in a numerical character reference). Secondly, browsers will tend to handle character entity references they know about more reliably than numerical character references, as character entity references can refer to a character without making assumptions about the character set or encoding. A user agent should understand the entity reference "quot" as the character with number 34, but even if it doesn't, it's still a quotation mark.

The downside of character entity references is again twofold: First, some of the names of character entity references are not easy to remember or even decipher - who can figure out that "raquo" stands for "right-pointing double angle quotation mark" (or even know what that is). Secondly, not all user agents understand all character entity references. HTML 4.0 may define a whole slew of these, but Netscape will probably crease its eyebrows at more than half of them.

The syntax for a character entity reference is an ampersand (&) followed by the name of the entity, followed by a semi-colon (;). Here are some examples:

<P>The pub we went to was named the &laquo;Horse &amp;
Carriage&raquo;. They served fine draught ale for just
&pound;1.20.</P>

The pub we went to was named the «Horse & Carriage». They served fine draught ale for just £1.20.

Since character entity references refer to characters in the document character set, it is generally better to use the actual character encoded in the document instead of using them, for the same reasons that numerical character references should be avoided. However, there is one important exception: Look at the example above again. What if I had used the ampersand character directly? A user agent reading the document might be mistaken into believing that it denoted a character reference. And what if I literally wanted to include the letters (&amp;) in my document? More importantly, what if I wanted to use the less-than or greater-than sign in my document, without implying that a tag begins or ends at that point? The answer is to use the character entity references &lt;, &gt; and &amp; whenever you want to insert a greater-than, less-than, or ampersand character in your document without implying an entity or character reference, or a tag. The following example illustrates this:

<P>Elementary mathematics states that 3 &lt; 5 &gt; 1.</P>
<P>To insert an ampersand in an HTML document, you should use the
syntax &amp;amp;</P>

Elementary mathematics states that 3 < 5 > 1.

To insert an ampersand in an HTML document, you should use the syntax &amp;

If I did not use named character entity references in the above example, a user agent would be mystified by the start-tag for the mysterious "5" element, and render the ampersand character entity reference as an ampersand, making the tutorial writer's job quite impossible. For this reason, you must always use character entity references when using the ampersand, greater-than and less-than characters in your documents.

index12345summary

http://www.internet.com/

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial17/5.html

Produced by Stephanos Piperoglou
Created: December 02, 1999
Revised: December 15, 1999

Morty Proxy This is a proxified and sanitized view of the page, visit original site.