HTML Entity Encoder
Escape text for safe use in HTML: & < > " and ' become entities, and optionally all non-ASCII or all special characters as numeric references.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the HTML Entity Encoder
- 1 Type or paste the text or code you want to show in HTML.
- 2 Choose what to encode and the number format.
- 3 Copy the escaped text into your HTML.
About the HTML Entity Encoder
Some characters have a special meaning in HTML: < starts a tag and & starts an entity. To show them as text, for example a code example on a web page, they must be written as entities: < > & and, inside attributes, " and '. That is also the basic protection against HTML injection when you put user input into a page.
"Only special characters" encodes exactly those five, which is enough for UTF-8 pages. "Also non-ASCII characters" writes every character above ASCII as a numeric reference such as é for é, which is useful for e-mail templates or systems that can’t handle UTF-8. "All characters" also encodes punctuation, leaving only letters, digits and whitespace.
Numeric references can be decimal (é) or hexadecimal (é); browsers understand both. To turn entities back into text, use the HTML Entity Decoder.
Frequently asked questions
Which characters must be escaped in HTML?
Always & and <. In attribute values also the quote you use around the value (" or '). > is escaped too for safety and readability.
Do I need entities for accents like é?
Not on a page served as UTF-8, which is nearly every modern page. They are only needed for systems or e-mails that don’t support UTF-8.
Decimal or hexadecimal references?
They mean exactly the same. Decimal (é) is more common; hexadecimal (é) matches the Unicode code point U+00E9.
Is this enough to prevent XSS?
Escaping & < > " ' is the right defence for text inside HTML elements and quoted attributes. JavaScript, URLs and CSS contexts need their own escaping.