What Are HTML Entities and Why Are They Used? Character Entities Explained

An HTML entity is a short code that stands for one character, such as `&lt;` for `<` or `&copy;` for `©`. The browser replaces the code with the character when it displays the page. Entities exist because some characters cannot simply be typed into HTML: either they mean something to the HTML parser, or they are invisible, or they are hard to type. This article explains each reason with an example, shows the three ways to write an entity, and clears up a question that often appears in coursework: what "character and paragraph entities" are.

What an HTML entity looks like

Every entity starts with an ampersand and ends with a semicolon. Between them is either a name or a number. All three lines below display the same copyright sign:

&copy;      named entity
&#169;      decimal numeric entity (Unicode code point 169)
&#xA9;      hexadecimal numeric entity (the same code point in hex)

The official term in the HTML standard is character reference, which is a better description: an entity does not add formatting or behaviour, it only refers to a single character (a few names produce two). Named references are easier to read; numeric ones work for every Unicode character, including the many that have no name. The HTML standard defines 2,125 names, from &amp; to rare mathematical symbols such as &NotSquareSupersetEqual;.

Reason 1: characters that HTML reserves

The < character starts a tag and & starts an entity. If you want to show them as text, the browser has to be told not to interpret them. Look at what happens to a sentence about comparison operators when it is written without entities:

<p><b>x</b> if a<b then</p>
<!-- displays: "x if a" — the browser read "<b then" as an opening tag -->

<p>5 &lt; 10 &amp;&amp; 10 &gt; 5</p>
<!-- displays: "5 < 10 && 10 > 5" -->

That is the main reason entities are used, and the five that matter most are &lt; (<), &gt; (>), &amp; (&), &quot; (") and &#39; or &apos; (\'). Quotes need escaping inside attribute values that use the same quote character. Writing them correctly is also a security measure. When a website shows text typed by users, every < must become &lt;, otherwise a user could insert a <script> element into the page. Server-side languages do it with functions such as PHP's htmlspecialchars:

echo htmlspecialchars('<script>alert("x")</script> & O\'Neil');
// &lt;script&gt;alert(&quot;x&quot;)&lt;/script&gt; &amp; O&#039;Neil

Reason 2: invisible and special spaces

HTML collapses whitespace. Five spaces in the source show as one, and a line break in the source is just another space. Some spaces and invisible characters therefore have to be written as entities to have any effect:

&nbsp;    no-break space: keeps "20 kg" or "Mr. Smith" on one line
&ensp;    en space, half as wide as the letter m
&emsp;    em space, as wide as the letter m
&thinsp;  thin space, used before units in some styles
&shy;     soft hyphen: invisible unless the word breaks there

&nbsp; is the most used entity on the web, and also the most misused. It is meant to stop a line break between two words, not to indent text or create gaps; for layout, use CSS margins and padding. &shy; is useful for long words in narrow columns, because it marks where the browser may hyphenate without showing a hyphen otherwise.

Reason 3: symbols that are hard to type

The third reason is practical: many symbols are not on a keyboard. Entities let you write them in plain ASCII source code, which also survives editors and systems that mishandle other encodings:

&copy; &reg; &trade;     © ® ™
&euro; &pound; &yen;     € £ ¥
&mdash; &ndash; &hellip; — – …
&rarr; &larr; &hearts;   → ← ♥
&frac12; &deg; &times;   ½ ° ×

Today almost every page is served as UTF-8, which can contain these characters directly. Typing © is perfectly valid HTML, so entities for symbols are a convenience rather than a requirement. They are still common in templates and e-mails, where you cannot be sure the file will keep its encoding, and for characters that look alike, such as the en dash and the minus sign.

"Character and paragraph entities": what the question means

School and university assignments often ask: "What are character and paragraph entities? How are they helpful in creating and formatting web pages?" The wording mixes two different things, and it helps to separate them in an answer.

Character entities are the entities described above: codes that insert one character, such as &lt;, &nbsp; or &copy;. They help in creating web pages because they let you display reserved characters safely, control spacing and line breaks, and include symbols that are not on the keyboard.

There is no separate category of "paragraph entities" in HTML. Paragraphs are created with elements, the <p> tag, plus <br> for a line break inside a paragraph, and they are formatted with CSS. The question usually refers to these paragraph tags, which textbooks sometimes group with character formatting tags. The only entity with "paragraph" in its name is &para;, which displays the pilcrow sign ¶ used by editors to mark a paragraph; it does not create one.

Named or numeric: which to use

Use named entities for the five reserved characters and for &nbsp;; everyone reading the source recognises them. For other characters, either write the character directly in UTF-8 or use a numeric reference, which works for every code point, even emoji such as &#x1F600; (😀). Two details trip people up. Names are case-sensitive, so &Eacute; (É) and &eacute; (é) are different characters. And the semicolon matters: a few old names such as &copy still work without it for compatibility, but most do not, and the HTML standard treats a missing semicolon as an error.

To check what a string will look like, or to convert text into safe entities, paste it into the HTML entities encoder and decoder. For decoding entities in code, see decoding HTML entities in JavaScript.

Sources and further reading

The WHATWG HTML Standard is the definitive reference: its "Character references" section defines the syntax and its named character reference table, also published as entities.json, lists every name. MDN's glossary entry for "Character reference" gives a short introduction. The W3C article "Using character escapes in markup and CSS" explains when to use escapes versus UTF-8 characters, and the OWASP Cross Site Scripting Prevention Cheat Sheet covers escaping for security. The PHP manual documents htmlspecialchars.

Frequently asked questions

What are HTML entities?

Codes that represent single characters in HTML, written as &name; or &#number;. The browser shows the character instead of the code, so &lt; displays as < and &copy; as ©.

Why are HTML entities used?

For three reasons: to show characters HTML reserves, such as < and &, as text; to insert invisible characters such as the no-break space; and to write symbols that are not on the keyboard. Escaping reserved characters also prevents script injection.

What are character entities in HTML?

Character entities are the codes that insert one character, for example &lt;, &nbsp;, &euro; or &#8364;. The HTML standard calls them character references and defines 2,125 named ones.

Are there paragraph entities in HTML?

No. Paragraphs are made with the <p> element and line breaks with <br>, and they are styled with CSS. The only related entity is &para;, which displays the ¶ sign without creating a paragraph.

What is the difference between named and numeric entities?

Named entities use a word, such as &copy;, and exist only for characters that have a name. Numeric entities use the Unicode code point, such as &#169; or &#xA9;, and work for any character.

Do I still need HTML entities with UTF-8?

Only for the reserved characters < > & and quotes, and for invisible characters such as &nbsp;. Symbols like © or € can be typed directly in a UTF-8 page.