HTML Encoder / Decoder
Escape HTML characters, or turn the escapes back into text.
Escape markup as text, or turn the escapes back. Not a sanitiser for innerHTML.
<p class="hi">Hello</p>
Calculations happen in your browser.
Worked example
<p class="hi">Hello</p> encodes to <p class="hi">Hello</p>. Decoding that string returns the original tags.
FAQ
- When should I encode HTML?
- When you need to show markup as text, or place untrusted text inside HTML, so tags aren’t treated as elements.
- Which characters are escaped?
- Ampersand, less-than, greater-than, and double quote. Apostrophes are left as-is.
- Is this a sanitiser for innerHTML?
- Encoding is the right step before inserting text. Don’t decode and then inject the result as HTML.