3.5: Entity codes add typographical sophistication

To add polish to your typography, pay attention to details, such as typesetter quotes (“”) and em dashes (—) as well as other special characters. Open the collapsible box at the top of this page for a comprehensive list.

Each letter you type in your HTML document uses eight bits, or one byte, of data. You will remember that the basic data unit of one byte allows for 256 combinations (28). This means you can type only 256 different characters in an HTML code document.

These 256 characters are determined by a standard used by Web browsers called ISO Latin-1. A subset of ISO Latin-1 are the 128 ASCII characters. ASCII stands for American Standard Code for Information Interchange.

All fonts have more than 256 characters, of course. The font Verdana uses 695 characters, including such things as scientific symbols. We overcome the 256-character limitation by using combinations of the basic 256 characters; the combinations are called escape sequences or entity codes, entities for short. Here is a piece of code you might type into an HTML document:

   <p>Copyright &#0169; 2003, University of St. Thomas</p>

And here is how it looks on the Web page:

Copyright © 2003, University of St. Thomas

&#0169; is the entity code for the copyright sign.

It and all other entities begin with an ampersand (&). As with most things Web, entities often can be expressed two ways. The first is by using an HTML ampersand sequence. It begins with an ampersand followed by a common-sense title (copy) and ending with a semicolon. Here’s the HTML ampersand sequence for the copyright symbol — &copy; — and here’s how it looks: ©

Because we are working in HTML5, we will use the latest standard in escape sequences. The complete list is available at W3Schools.

Typographical polish

Look at these paragraphs that do not use entities; pay attention to punctuation:

At last some four or five of us were summoned to our meal in an adjoining room. It was cold as Iceland -- no fire at all -- the landlord said he couldn't afford it. Nothing but two dismal tallow candles, each in a winding sheet. We were fain to button up our monkey jackets, and hold to our lips cups of scalding tea with our half frozen fingers. But the fare was of the most substantial kind -- not only meat and potatoes, but dumplings; good heavens! dumplings for supper! One young fellow in a green box coat, addressed himself to these dumplings in a most direful manner.

'My boy,' said the landlord, 'you'll have the nightmare to a dead sartainty.'

'Landlord,' I whispered, that aint the harpooneer, is it?'

'Oh, no,' said he, looking a sort of diabolically funny, 'the harpooneer is a dark complexioned chap. He never eats dumplings, he don't -- he eats nothing but steaks, and likes 'em rare.'


Here is the code for the same paragraphs with entities in place:

<p>At last some four or five of us were summoned to our meal 
in an adjoining room. It was cold as Iceland &#8212; no fire at all 
&#8212; the landlord said he couldn&#8216;t afford it. 
Nothing but two dismal tallow candles, each in a winding sheet. We 
were fain to button up our monkey jackets, and hold to our lips cups 
of scalding tea with our half frozen fingers. But the fare was of the 
most substantial kind &#8212; not only meat and potatoes, but dumplings; 
good heavens! dumplings for supper! One young fellow in a green 
box coat, addressed himself to these dumplings in a most direful 
manner.</p>

<p> &#8216;My boy,&#8216; said the landlord, &#8216;you&#8216;ll 
have the nightmare to a dead sartainty.&#8216;</p>

<p> &#8216;Landlord,&#8216; I whispered, 
&#8216;that aint the harpooneer, is it?&#8216;</p>

<p> &#8216;Oh, no,&#8216; said he, looking a sort 
of diabolically funny, &#8216;the harpooneer is a dark 
complexioned chap. He never eats dumplings, he don&#8216;t
&#8212; he eats nothing but steaks, and likes &#8216;em
rare.&#8216;</p>

Here is how the text with entities looks in the browser:

At last some four or five of us were summoned to our meal in an adjoining room. It was cold as Iceland — no fire at all — the landlord said he couldn’t afford it. Nothing but two dismal tallow candles, each in a winding sheet. We were fain to button up our monkey jackets, and hold to our lips cups of scalding tea with our half frozen fingers. But the fare was of the most substantial kind — not only meat and potatoes, but dumplings; good heavens! dumplings for supper! One young fellow in a green box coat, addressed himself to these dumplings in a most direful manner.

‘My boy,’ said the landlord, ‘you’ll have the nightmare to a dead sartainty.’

‘Landlord,’ I whispered, ‘that aint the harpooneer, is it?’

‘Oh, no,’ said he, looking a sort of diabolically funny, ‘the harpooneer is a dark complexioned chap. He never eats dumplings, he don’t — he eats nothing but steaks, and likes ’em rare.‘