What is HTML Entity?

An HTML entity is a coded representation of a character used to display reserved or special symbols in HTML without breaking the markup.

An HTML entity is a special sequence of characters used to represent a symbol in HTML that would otherwise be interpreted as markup or is difficult to type directly. Entities begin with an ampersand and end with a semicolon, with either a name or a numeric code in between - for example & for an ampersand, < for a less-than sign, and © for the copyright symbol.

Entities exist to solve two problems. First, certain characters are reserved by HTML itself: the less-than and greater-than signs delimit tags, and the ampersand starts an entity. To display these literally as text, you must escape them as <, >, and &, otherwise the browser tries to interpret them as structure and the page breaks or renders incorrectly.

Second, entities let you include characters that are hard to type or that might not survive certain encodings - accented letters, mathematical symbols, currency signs, arrows, and emoji. Named entities like € are readable, while numeric entities such as € (decimal) or € (hexadecimal) can represent any Unicode code point, making them a universal fallback.

Encoding and decoding entities is a routine task when handling user-generated content, preventing cross-site scripting by escaping untrusted input, or cleaning scraped HTML back into plain text. A frequent bug is double-encoding, where & appears because content was escaped twice. Understanding when text needs to be encoded for safe display versus decoded for readability avoids these mix-ups.

Examples

  • &lt; and &gt; display literal < and > without being treated as tags
  • &amp; displays a literal ampersand
  • &#8364; and &euro; both render the euro sign €

Common questions

Which characters must always be escaped in HTML?
The ampersand (&amp;), less-than (&lt;), and greater-than (&gt;) at minimum, plus quotes (&quot; and &#39;) inside attribute values. Escaping these prevents the browser from misreading text as markup.
What is double-encoding?
Double-encoding happens when already-escaped content is escaped again, producing sequences like &amp;amp; that display the literal '&amp;'. It usually means content was encoded at two different stages of processing.
What is the difference between named and numeric entities?
Named entities like &copy; are human-readable but limited to a defined set. Numeric entities like &#169; reference a character by its Unicode code point and can represent any character, making them a universal option.

Related tools

Related terms for HTML Entity