$devtoolkit.sh/glossary/what-is-html-entities

What are HTML Entities? — Character References Explained

Definition

HTML entities are special text sequences used to represent characters that either have special meaning in HTML markup (like < and >) or that cannot be typed directly. An entity begins with & and ends with ;, and can use either a named reference like &amp; or a numeric reference like &#38; (decimal) or &#x26; (hexadecimal). They were essential in early HTML when encodings were inconsistent, and they remain necessary for certain reserved characters.

How It Works

When an HTML parser encounters & in text content, it reads characters until it finds a ;, then looks up the full entity name or numeric code in its entity table and substitutes the corresponding Unicode character. For characters that are reserved in HTML (< > & " '), using their entity equivalents prevents them from being interpreted as markup. For example, &lt; tells the parser to display < as text rather than interpret it as the start of a tag. Modern HTML5 documents with a declared UTF-8 charset can include most Unicode characters directly, so entities are mainly needed for <, >, &, ", and a few others.

Common Use Cases

  • Displaying < and > as literal characters in HTML without starting a tag
  • Preventing cross-site scripting (XSS) by escaping user input before rendering in HTML
  • Including the copyright © or trademark ™ symbol in older documents
  • Embedding non-breaking spaces &nbsp; to control text layout
  • Representing characters from scripts not easily typeable on a keyboard

Example

<p>5 &lt; 10 &amp;&amp; 10 &gt; 5</p>
Renders as: "5 < 10 && 10 > 5"

&copy; → ©
&nbsp; → non-breaking space
&#9829; → ♥

Related Tools

FAQ

Should I use named or numeric HTML entities?
Named entities like &amp; and &lt; are more readable and universally supported for the common reserved characters. Numeric entities are useful for characters that do not have a named form or when working in environments that do not decode named entities.
Do I need entities in a UTF-8 HTML5 page?
In a UTF-8 HTML5 document you only need entities for the five reserved characters: < &lt; > &gt; & &amp; " &quot; and ' &apos;. All other Unicode characters can be included directly in the source.
What is the &nbsp; entity used for?
&nbsp; is a non-breaking space. Unlike a regular space, it prevents a line break at that position. It is often used to keep two words together on the same line, like "10&nbsp;km".

Related Terms

/glossary/what-is-html-entitiesv1.0.0