HTML entity encoder and decoder
Escape text so it shows as text in HTML, or turn entities like & and é back into characters. Decoding runs as plain text processing, never as HTML.
Worked example
A snippet of HTML escaped with named entities, so it can be shown as code on a web page.
<a href="/?q=fish&chips">Fish & chips</a>
<a href="/?q=fish&chips">Fish & chips</a>
Common mistakes
Escaping twice
Encoding already-escaped text turns & into &amp;, which shows up on the page as “&”. Decode first if you aren’t sure.
Forgetting the semicolon
© without the semicolon only works by accident for a few old names. Always write ©.
Escaping only < and >
An unescaped & or quote can still break an attribute value or start an entity. Escape all five special characters.
Using entities to stop script injection in JavaScript or URLs
HTML escaping protects HTML text and attributes. Inside a <script> block, a URL or CSS, each context needs its own escaping.
How it works
- 1
Choose Encode or Decode
Encode escapes & < > " and ' so a browser shows them instead of treating them as markup. Decode reverses it.
- 2
Pick a style
Named entities (<), decimal (<) or hex (<). Turn on Encode non-ASCII to also escape accented letters, symbols and emoji.
- 3
Copy the result
Switching direction moves the output into the input, so you can check a round trip in one click.
Questions
- Which characters must be escaped in HTML?
- In text, & and < always; > for safety. Inside attribute values, also the quote you used around the value. This tool escapes all five (& < > " ') so the result is safe in both places.
- Why is the apostrophe written as ' and not '?
- ' came with XHTML and HTML5 and isn’t in HTML 4, so some older software doesn’t know it. ' works everywhere. The decoder understands both.
- Which named entities does the decoder know?
- The full HTML 4 set of 252 names, from and © to Greek letters, arrows and math symbols, plus '. Any numeric entity works. Unknown names are left as written and listed above the output.
- Do I need entities for accents and emoji?
- Not if the page is served as UTF-8, which almost every page is. Escape them only when the text has to pass through a system that mangles non-ASCII characters.
- Is it safe to decode untrusted text here?
- Yes. Decoding is a lookup in a table; the text is never put into the page as HTML, so a decoded <script> tag is only text.