HTML Entity Encoder and Decoder
Convert characters to HTML entities and back, so markup displays as text instead of being parsed as tags.
Everything you type here is processed on your own device. No input is sent to a server, logged, or stored.
What the HTML Entity Encoder and Decoder does
The HTML entity encoder and decoder on this page will convert characters to HTML entities and back, so markup displays as text instead of being parsed as tags. Paste your text in, pick the options you need, and copy the result straight back out. It is most often used for displaying a code sample inside a web page. For a second version of this HTML entity encoder and decoder, see FreeToolsWorld.org.
How to use it
- Paste your text or markup.
- Encode to make the characters display literally in a web page.
- Decode to turn entities back into the characters they represent.
- Copy the result into your template or document.
How it works
Five characters need escaping in HTML: & < > " and '. Escaping them is what stops a browser from interpreting user-supplied text as markup, which is the mechanism behind most cross-site scripting vulnerabilities.
The ampersand must be escaped first and unescaped last, otherwise &lt; and < become indistinguishable. This tool handles that ordering correctly in both directions, which is a common bug in hand-rolled escaping functions.
This is a formatting aid, not a security control. In an application, escape at the point of output using your template engine's built-in escaping, which knows the context — attribute values, URLs and inline scripts each need different treatment, and a single escape function cannot cover all three.
When to use it
- Displaying a code sample inside a web page.
- Reading text where entities have been double-encoded.
- Preparing content with special characters for an HTML email.
Common mistakes to avoid
- Relying on client-side escaping for security instead of escaping server-side at render time.
- Escaping an already-escaped string, which turns & into &amp;.
- Using HTML escaping for a value that goes into a URL or a script block, which need different encoding.
Frequently asked questions
Does escaping prevent XSS?
Correct context-aware escaping at render time is the main defence, but it must happen in your application, not in a browser tool. Different contexts — HTML body, attribute, URL, JavaScript — require different escaping rules.
Why is my text showing &amp;?
It has been escaped twice. Decode once to get back to & and once more for the literal ampersand. Find and fix the double-escaping in your pipeline.