Encode and decode HTML entities
Paste text to escape it for a page, or paste HTML full of entities to read it as plain text. Decoding follows the rules a browser uses for the text of a page, including the old names written without a semicolon, and the result updates as you type.
How to use it#
- Paste your text to escape it, or press the swap arrows first to unescape entities instead.
- Choose which characters to encode: only the five HTML gives a meaning, those and every non-ASCII character, or every character but spaces and line breaks.
- Choose whether each is written as a name, such as é, a decimal number, or a hex number, then copy the result. When decoding shows text that was encoded twice, press Decode again.
Which characters have to be encoded#
Two of the HTML special characters always need it in the text of a page: the ampersand, which starts an entity, and the less-than sign, which starts a tag. Inside an attribute value, the quote that wraps the value needs it too, " for double quotes and ' for single. The greater-than sign is safe on its own but is encoded by convention, so the default here encodes all five: & < > " and '.
Accented letters, symbols, and emoji do not need encoding on a page saved and served as UTF-8, which is nearly every page made today. Writing café as "café" changes nothing a reader sees. The second option is for places that are not UTF-8 or might not stay so: an email template passed through older systems, a CMS field that mangles accents, or a feed declared as ASCII. "Every character" encodes the letters too, which is mainly useful for reading code points or hiding an address from simple scrapers.
Encoding is for HTML only. A value going into a link needs percent-encoding, which the URL encoder does, and text going into a JavaScript or JSON string needs backslash escapes, which JSON escape writes.
Names or numbers#
The HTML standard lists 2,231 named references, from Æ to ‌, but most characters have no name, while every character has a number. A decimal reference such as é and a hex one such as é mean the same é. Hex matches the U+00E9 you see in character tables, and decimal is what older tools tend to write.
Names are easier to read in source, so the named form uses one wherever it exists and falls back to a decimal number for anything without one, such as most emoji. Where a character has several names it picks the one HTML 4 already had, → rather than →, since that is the name every browser and editor knows. In the named and decimal forms the apostrophe is written ', because ' was not part of HTML 4.
XML knows only five names: <, >, &, ", and '. A name such as é or in an RSS feed, an SVG file, or any other XML stops the parser, so choose decimal or hex for anything that is not HTML.
How decoding reads what you paste#
Decoding works as a browser reads the text of a page. Every named reference with its semicolon is turned back, along with decimal and hex numbers, with or without a capital X. The 106 legacy names also work without a semicolon, so "©2024" reads as "©2024", and "&" alone as an ampersand. A browser treats them the same way in text, which is why a stray © in a sentence can surprise you.
Numbers follow the standard too. The numbers 128 to 159 are read as the Windows-1252 characters older pages meant by them, so – is an en dash and ™ a trademark sign. Zero, numbers past the last code point, and the halves reserved for surrogate pairs become the replacement character �.
Something written like an entity that the standard has no name for, such as &foo;, is left as it was and named in a line under the result, so you can see which part of the text did not decode.
Text that was encoded twice#
A page that shows &lt;p&gt; or &quot; to its readers has been escaped twice: once by the code that saved the text and again by the template that printed it. The first pass turned < into <, the second turned its ampersand into &, and the browser undoes only one layer.
When the decoded result still holds entities, the page says so, and Decode again turns the result back one more layer. To fix it at the source, find where text is escaped before it is stored and leave that to the template, which knows it is writing HTML.
Frequently asked questions#
What is the difference between and a normal space?
#
A no-break space looks like a space but keeps the words on either side on one line, and it is not collapsed when several sit together. It is useful between a number and its unit, as in 10 kg. It is a character of its own, U+00A0, so text copied from a page with it may fail a search for a plain space.
Do I need to encode accented letters and emoji?
#
Not on a page served as UTF-8, which most are. They can be written as they are, and the page is shorter and easier to edit that way. Encode them when the text passes through something that is not UTF-8, such as an older email system, or when an editor or database has mangled them before.
Is ' a valid entity?
#
In HTML today and in XML, yes. It was missing from HTML 4, so an old browser or email client could show it as written, which is why this page writes the apostrophe as a number, ' or '. Decoding reads both.
Why did "©" in my link turn into ©?
#
The oldest names, such as copy, reg, and amp, are read even without a semicolon, so text such as "?a=1©=2" decodes with a © in it here. This page reads entities as a browser reads the text of a page. Inside an attribute such as href, a browser leaves a name without its semicolon alone when a letter, digit, or = follows it, so the link itself works. Writing every & in a URL as & avoids the question either way.
Does encoding these characters stop XSS?
#
Encoding & < > " and ' keeps text from turning into tags in the body of a page and in attribute values wrapped in quotes, which is where most user text lands. It does not protect text placed inside a script, a style block, an unquoted attribute, or a URL such as an href, where a javascript: link needs no special characters at all. Each of those needs its own escaping, and a template engine that escapes by context does it for you.
Why does my page show &amp; or <p> as text?
#
The text was encoded twice, so the browser undoes one layer and shows the other. Paste it here to decode it; if the result still holds entities, the page says so, and Decode again takes off the next layer.