HTML uses a few characters as its own syntax: < starts a tag, & starts an entity, and quotes surround attribute values. To show those characters as ordinary text, you write them as entities — short codes that begin with & and end with ;. This guide explains which characters need it, the different kinds of entities, and why getting this right is a security issue. To convert text in either direction, use the free HTML Entity Encoder / Decoder.
The five characters that matter
| Character | Entity | Why |
|---|---|---|
& | & | Starts an entity |
| `` | > | Ends a tag (escaping it is good practice) |
" | " | Ends a double-quoted attribute |
' | ' | Ends a single-quoted attribute |
If you want a web page to show the code <div class="box">, you must write:
<div class="box">Otherwise the browser creates a real div instead of displaying the text.
Why ' rather than '? The name ' exists in XML and HTML5 but not in the older HTML 4 standard, so the numeric form is the safest choice everywhere.
Named and numeric entities
There are three ways to write the same character:
| Form | Example for © | Example for ₹ |
|---|---|---|
| Named | © | (no common name) |
| Decimal | © | ₹ |
| Hexadecimal | © | ₹ |
Named entities are easy to read but only exist for some characters: ©, ®, ™, €, £, , — and a few hundred more. HTML5 added many names, including names for ordinary punctuation such as , and . — valid in HTML5, but unknown to older and XML parsers.
Numeric entities work for every Unicode character. The number is the character's Unicode code point, in decimal or in hex after &#x.
Do you still need entities with UTF-8?
For most characters, no. If your page is saved as UTF-8 and declares `` — as every modern page should — you can type ©, €, ₹, é, हिंदी or emoji directly. Entities for those were essential when pages used older character sets; today they are optional.
You still need them for:
- The five syntax characters above, whenever they should appear as text
- Invisible or ambiguous characters, where an entity makes the source clearer:
(non-breaking space) or­(soft hyphen) - Systems that mangle non-ASCII text, such as some older email tools, where
©survives better than ©
Escaping and XSS
Cross-site scripting (XSS) happens when text from a user is placed in a page without escaping. If a comment form stores steal() and the page prints it as-is, the script runs in every visitor's browser. Escaped, it is printed harmlessly as text.
That is why output encoding — escaping the five characters every time user data is written into HTML — is the foundation of XSS prevention. In practice:
- Let your template engine or framework do it. React, Vue, Angular, Django, Jinja, Laravel Blade and Rails all escape output by default.
- Be careful with the escape hatches:
dangerouslySetInnerHTML,v-html,|safe,{!! !!}andinnerHTMLall skip escaping. - Remember that context matters. Escaping for HTML text is not enough inside a `` block, a URL or a CSS value; each needs its own encoding.
- Manual encoding with a tool is great for content and code samples, but it is not a substitute for automatic escaping in an application.
Decoding entities
Decoding turns entities back into characters — useful when data from a feed, an API or a CMS export arrives as Men's Shoes & Socks and you need plain text. The HTML Entity Encoder / Decoder decodes all numeric entities plus the common named ones; rare names such as … and ’ are left in place for you to check.
Double encoding
If you see & or < on a page, text was escaped twice — often once when saved and again when displayed. Decode until the text reads normally, then make sure your code escapes only once, at output time.
Quick reference
- Writing code samples in a blog post: encode
&. - Putting text into an attribute: encode
" ' &. - Typing ©, ₹ or é in a UTF-8 page: no entity needed.
- Building a link: that is URL encoding, not entities — see URL encoding explained.
- Writing \u escapes for JavaScript or JSON: use the Unicode Converter.



