How to Encode and Decode HTML Entities
Updated 2026-06-21
To encode HTML entities, replace reserved characters with their entity equivalents: an ampersand becomes &, a less-than sign becomes <, a greater-than sign becomes >, and a double quote becomes ". To decode, you reverse the process — turning each entity back into the character it represents.
Why HTML entities exist
A browser reads certain characters as markup, not as text. A literal less-than sign can start a tag, and a bare ampersand can begin an entity reference. If you want those characters to appear as text on the page, you have to escape them so the browser shows the symbol instead of trying to interpret it.
The four reserved characters you almost always need to encode are:
- Ampersand (&) → &
- Less-than (<) → <
- Greater-than (>) → >
- Double quote (") → "
Single quotes are sometimes written as ' (numeric) rather than ', since the named version is not reliable in older HTML.
Named, decimal and hex — three ways to write one character
Every entity can be expressed three ways, and they all render identically:
- Named — a human-readable label, like © for the copyright symbol.
- Decimal — an ampersand, a hash, the character's Unicode code point in base 10, and a semicolon. The copyright symbol is ©.
- Hexadecimal — the same, but with an x and the code point in base 16: ©.
Named entities are the most readable but only exist for a fixed set of characters. Decimal and hex work for any Unicode code point, which makes them the safe choice for emoji, accented letters, mathematical symbols, or anything outside the named list. The HTML Entity Encoder / Decoder lets you choose which format you want when encoding.
A worked example
Say you want to display this line of code as text on a page: the snippet a & b < c. If you paste it raw into your HTML, the browser may swallow part of it. Encoded, it becomes a & b < c, which renders back to exactly what you typed.
Going the other direction, if you copy text out of a database or an email and see &quot; or ’ scattered through it, decoding turns those back into readable quotes and apostrophes.
Common pitfalls
- Double-encoding. If you encode text that is already encoded, & becomes &amp; and shows up literally on the page. Decode first if you are unsure.
- Forgetting the ampersand itself. Always encode & before the others, or you will mangle the entities you just created.
- Attribute values. Inside an HTML attribute, encode the quote character that wraps it, plus any ampersands.
Everything in the tool runs entirely in your browser — your text is never uploaded, which matters when you are escaping snippets from private code, internal docs, or customer data.
Ready to convert? Open the HTML Entity Encoder / Decoder and paste your text to encode or decode it instantly.