Text in HTML: Displaying Special Characters

Sometimes, it is necessary to include HTML characters, such as <, > and &, in a page. This may be, for example, because you are building an HTML tutorial Web page. In order to ensure that the browser does not interpret the characters as HTML code, character entity references or numeric character references (also known as escape characters or escape codes) are used. These references also enable characters that are not available on the computer keyboard, such as copyright symbol, to be displayed in a Web page. Character entity references are case-sensitive and take the format &name;. Therefore, a left-angled bracket, for example, is written as &lt; and a right-angled bracket is written as &gt;. This means to output <html>, for example, &lt;html&gt; is written.

Numeric character references are specified in decimal or hexadecimal numbers; however, decimal numeral system is the most commonly supported by browsers. The decimal numeral system is a system of counting in 10s, while the hexadecimal numeral system is a system of counting in 16s, in which after counting from 0 to 9, the rest of the count is done with letters (i.e., A to F). Therefore, a count from 0 to 16 is 0-9 A-F, that is, 0 1 2 3 4 5 6 7 8 9 A B C D E F. In decimal numeral system, numeric character references take the format &#number;, and in hexadecimal numeral system, they take the format &#xnumber;. For example, the copyright symbol, ©, is “&#169;” in decimal and “©” in hexadecimal numeral system (which is also the Unicode). Because not all typefaces support all character references, it is important that one that supports the required characters is used. Table 3.4 lists a range of characters. For more references, you can do a quick search for “Character entity references” on the Web, and the Unicode codes for various characters can be found at unicode.org/charts. Figure 3.38 shows how the references are used, and Figure 3.39 depicts the rendered output. Notice how in the output, &POUND is not converted to the pound sign. This is because it is in all uppercase, when it should actually be in all lowercase.

Source: Sklar David (2016), HTML: A Gentle Introduction to the Web’s Most Popular Language, O’Reilly Media; 1st edition.

Leave a Reply

Your email address will not be published. Required fields are marked *