How to Use Special Characters in HTML

Move Your Site Beyond Plain Text

Math Symbols on Chalk Board
Alex Belomlinsky/iStock Vectors/Getty Images

When you’re using HTML, you can type most text characters without using any special codes. But how do you render the text elements that HTML uses to be HTML, like < and >? And what about characters that don’t have a direct analog on the keyboard, like © and Ñ?

These are called “special characters,” and HTML renders them with numeric or character encoding so that they can be included in an HTML document.

Special HTML Characters

There are three characters that you should never leave unencoded within your HTML documents. In other words, you should never write < in your HTML code unless it is the start of an HTML tag. If you do, they can confuse the browsers and your pages may not render as you expect. These characters are:

  • less-than sign <
  • greater-than sign >
  • ampersand &

Instead of typing these characters directly into your HTML code, you should type in the HTML encoding for them:

  • less-than sign &lt;
  • greater-than sign &gt;
  • ampersand &amp;

Special Characters You Can’t Type

Any character that can be rendered in the Latin-1 standard character set, can be rendered in HTML. You simply use the ampersand (&) with the friendly code for the character you want to use.

For example the friendly code for Ñ is &Ntilde;.

But there are a lot of characters that don't have a friendly code. What then?

Every character that can be typed on the screen has a corresponding numerical code.

You can use this numerical code to display any character. For example, the numerical code for Ñ is &#209;.

I prefer to use the numerical codes most of the time because they are more reliable. Sites that are built with databases and XML might not have all the friendly codes defined, but the numerical codes are automatic.

The best way to find the numeric codes for characters is in character sets.

Some character sets include:

Non-English Language Characters

There are also a lot of characters in non-English languages that can be expressed in HTML.