If you have ever typed <b> into a web page and watched your text turn bold instead of showing the characters, you have met the reason HTML entities exist. They let you display characters that HTML would otherwise treat as code, and they play a quiet but vital role in website security. So what are HTML entities, and when do you actually need them?
The definition
An HTML entity is a short code that represents a character. It starts with & and ends with ;. Browsers display the character, not the code.
Entities come in two forms:
- Named:
<for < - Numeric:
<(decimal) or<(hexadecimal) for the same character
The five you must know
These characters have special meaning in HTML, so they must be written as entities when you want to show them as text – a process called using escape characters:
<→ <>→ >&→ &"→ "'→ ' (apostrophe)
Example: to show the text <p> on a coding tutorial, write <p>.
Useful special symbols
– a non-breaking space, which stops two words being split across lines (for example, "10 kg")©– ©®– ®™– ™€– €£– £₦– ₦ (the naira sign)…– …—– —
Do you still need entities in modern HTML?
If your page uses UTF-8 encoding (which almost all modern sites do), you can type most special symbols such as €, ₦ or é directly. Entities remain essential for the five reserved characters, for invisible characters like non-breaking spaces, and anywhere you are not sure the encoding will survive, such as some email templates. Read what is ASCII for how character encodings work.
The security side: preventing XSS
Cross-site scripting (XSS) is one of the most common web vulnerabilities. If a website shows user input – a comment, a name, a search term – without escaping it, an attacker can submit something like:
<script>stealCookies()</script>
and the browser will run it for every visitor. Converting < and > to < and > turns the attack into harmless text.
Modern frameworks escape output automatically – Laravel's Blade {{ }}, React's JSX and Django templates all do. The danger comes when developers bypass this to print raw HTML. Only output raw HTML you fully control or have sanitised.
Entities in other places
- XML uses the same five entities.
- URLs use a different system, percent-encoding – see what is URL encoding.
- JSON uses backslash escapes such as
\"– see how to format JSON.
Encode and decode instantly
The free HTML Entity Encoder converts text to entities and back, handling named and numeric forms. It is useful for writing code tutorials, preparing email templates and checking what a strange code such as ’ means.
Related tools: URL Encode and Decode, Base64 Encode and Decode and the ASCII Converter.
Frequently asked questions
Are entity names case-sensitive?
Yes. É (É) and é (é) are different characters.
What does ’ mean? It is a right single quotation mark (’), often produced by word processors' "smart quotes".
Do I need to escape > as well as <? It is good practice for both, especially inside attribute values and user-generated content.
Why does my email show & instead of &? The text was escaped twice – once by one system and again by another. Decode it once with the tool, then make sure only the final output step escapes characters.
Can entities be used in page titles and meta descriptions? Yes, and they are often necessary there. An ampersand in a title, for example, should be written as an entity in the HTML source so the page stays valid; browsers and search engines display the normal character.
Summary
So, what are HTML entities? Codes beginning with & and ending with ; that display characters HTML would otherwise treat as markup, plus invisible and special symbols. Always escape <, >, & and quotes in user content to prevent XSS. Convert text both ways with the free HTML Entity Encoder.