Skip to main content

HTML Entities

Reserved characters in HTML must be replaced with entities. For example, the less-than sign < is written as &lt;, and the greater-than sign > is written as &gt;.


HTML Character Entities

Some characters are reserved in HTML. If you use the less-than (<) or greater-than (>) signs in your text, the browser might mistake them for tags.

You can show reserved characters using an entity name, written as &entity_name;, or an entity number, written as &#entity_number;. For example, a less-than sign can be written as &lt; or &#60;. Entity names are easier to remember than entity numbers.


Non-breaking Space

A common entity is the non-breaking space, &nbsp;. It is a space that will not break into a new line, so two words joined by it stay together, which is handy when a line break would be disruptive (for example in "10 km/h" or "10 PM").

It also prevents the browser from collapsing spaces. If you type 10 spaces, the browser keeps only one; to add real spaces, use &nbsp;. There is also a non-breaking hyphen, &#8209;, which is a hyphen that will not break onto a new line.


Some Useful HTML Character Entities

Some common entities (character, name, number): non-breaking space (&nbsp;, &#160;), less than (&lt;, &#60;), greater than (&gt;, &#62;), ampersand (&amp;, &#38;), double quote (&quot;, &#34;), single quote (&apos;, &#39;), cent (&cent;, &#162;), pound (&pound;, &#163;), yen (&yen;, &#165;), euro (&euro;, &#8364;), copyright (&copy;, &#169;), registered trademark (&reg;, &#174;), and trademark (&trade;, &#8482;).


Note

Entity names are case sensitive.


Combining Diacritical Marks

A diacritical mark is a glyph added to a letter. Some marks, like the grave and acute accents, are called accents. You can combine a mark with a letter to make a character that is not in the page's character set.

For example, a&#768; produces à, a&#769; produces á, a&#770; produces â, and a&#771; produces ã. The same marks work on other letters, so O&#768; produces Ò, and so on. There are more examples in the next chapter.