About the HTML Entity Encoder
Show code on a web page or put user text inside HTML safely by escaping the characters that HTML treats as markup.
HTML uses a handful of characters as markup: < and > open and close tags, & starts an entity, and quotes wrap attribute values. If you want those characters to appear as text, for example when showing code samples in a blog post, writing about HTML or placing user-supplied text inside a page, they must be escaped as entities such as < and &. Otherwise the browser treats them as code, which breaks layouts or, in the worst case, opens the door to cross-site scripting.
This tool encodes & < > " and ' into their entity forms, and can optionally encode every non-ASCII character (é, ©, emoji, Urdu letters) as numeric entities for systems that only accept plain ASCII. In Decode mode it turns entities back into characters, including all named entities your browser knows, such as ©, and —.
How to use the HTML Entity Encoder
- 1Choose Encode or Decode.
- 2Paste your text.
- 3Copy the result.
Key features
- Encode the five HTML special characters.
- Optional numeric entities for all non-ASCII characters.
- Decode named and numeric entities.
- Instant two-way conversion.
- Copy the result in one click.
Practical uses
- Displaying HTML or XML code examples on a web page.
- Preparing text for old systems that only accept ASCII.
- Reading entity-filled text from an RSS feed or database.
- Checking how a CMS stored special characters.
Example
The snippet <a href="/">Home & About</a> encodes to <a href="/">Home & About</a>, which a browser displays as the literal code instead of a link.
Tips and common mistakes
- Encode once only; encoding already-encoded text produces &lt; and similar double escapes.
- Inside <pre><code> blocks you still need to escape < and &.
- Let your framework escape user input automatically rather than doing it by hand in production.
Limitations
- Escaping for JavaScript strings, URLs and CSS needs different rules.
- It does not sanitise HTML; to clean untrusted HTML, use a sanitiser library.
Privacy
Encoding and decoding happen in your browser.
Frequently asked questions
Which characters are encoded?
& < > " and ' are always encoded. You can also encode every non-ASCII character as a numeric entity.
Does this protect against XSS?
Escaping output is an important part of XSS protection, but your framework or server should do it automatically for every value.
Can it decode named entities like ©?
Yes. All named entities known to your browser are decoded.
What is ?
A non-breaking space: it looks like a normal space but stops the line from breaking at that point.
Should I encode apostrophes?
Inside attribute values wrapped in single quotes, yes. The tool encodes them as ' to be safe everywhere.