JavaScript Tutorial

HTML Entities

HTML character entities are used as a replacement for reserved characters in HTML. You can also replace characters that are not present on your keyboard with entities.

These characters are replaced because some characters are reserved in HTML. HTML entities provide a wide range of characters that allow you to add icons, geometric shapes, mathematical operators, etc.

For example, if you use less than (<) or greater than (>) symbols in your text, the browser can mix them with tags, which is why character entities are used in HTML to display reserved characters.

The main benefits of HTML entities are that they are easy to use and remember, and they replace characters that are not on the keyboard. Here we will discuss different types of entities and provide basic examples to illustrate their functionality.

Warning! Entity names are case-sensitive.

Syntax for entities

The HTML <base> element is used to specify the base URL and base target for all relative URLs on a page.

&entity_name;

  OR

&#entity_number;

Names are easier to remember than numbers. Not all browsers are compatible with reserved names, but entity numbers work on all browsers. Browsers that do not support a symbol display it as boxes.

HTML entities are widely used in areas like foreign languages (European languages), punctuation elements, Greek characters, mathematical symbols, and shapes and arrows.

Entity codes are important to avoid strange errors that can be difficult to pinpoint. HTML entities are organized into lists such as letters/symbols with accents using Unicode, phonetics, foreign characters, currency, and other symbols like smart quotes (which are with straight long dashes).

Reserved Characters

Some special characters are reserved for use in HTML, which means your browser will parse them as HTML code. To display these characters as text, replace them with their corresponding character entities, as shown in the following table:

Character Entity Note
& &amp; Interpreted as the beginning of an entity or character reference.
< &lt; Interpreted as the beginning of a tag
> &gt; Interpreted as the ending of a tag
" &quot; Interpreted as the beginning and end of an attribute's value.

See also

Official list of character entities.

Go back to Previous Course