Developer Tools
HTML Encoder
Convert &, <, >, double quotes and apostrophes into HTML character references. This encoder is not a sanitizer; XSS safety depends on the output context.
About this tool
Convert &, <, >, double quotes and apostrophes into HTML character references. This encoder is not a sanitizer; XSS safety depends on the output context.
What is it?
HTML encoding converts characters to entity forms. Sanitization removes disallowed markup or attributes. This tool encodes text; it is not a sanitizer and does not solve every XSS problem.
How to Encode HTML Characters
Enter text and choose Encode. The tool converts ampersands, angle brackets, double quotes and apostrophes to HTML character references.
- Paste text or markup that contains characters to encode.
- Choose Encode to replace ampersand, angle brackets and double quotes with named references, and apostrophes with a decimal numeric reference.
- Review the text output; encoding does not sanitize HTML or cover every output context.
- Use the HTML Decoder only when you intentionally need to convert these entities back.
Examples
- <div>Hello</div> β <div>Hello</div>
- "A & B" β "A & B"
- It's ready β It's ready
Common use cases
- Escaping markup-like text before displaying it in an HTML text context that expects encoded content.
- Making ampersands and quotes visible in documentation examples.
- Preparing a string for a known HTML text context, followed by context-specific security review.
Technical details
- The implementation replaces &, <, > and double quote with the named references &, <, > and "; apostrophe becomes the decimal numeric reference '.
- These replacements run in order, preserve other characters and whitespace, and encode an existing ampersand again.
- Encoding is not sanitization. HTML text, attribute, URL, JavaScript and CSS contexts have different output-encoding requirements.
- This browser-side tool writes the result to a textarea; it does not send the input to the server or insert the result as HTML.
Related concepts
HTML Encoding Is Not HTML Sanitization
HTML encoding converts characters to entity forms. Sanitization removes disallowed markup or attributes. This tool encodes text; it is not a sanitizer and does not solve every XSS problem.
Frequently Asked Questions
Which characters and entity forms are produced?
Ampersand becomes &, angle brackets become < and >, double quote becomes ", and apostrophe becomes '. Other characters and whitespace are retained.
Does this tool prevent XSS or sanitize HTML?
No. Encoding can help in the correct HTML text context, but URL, JavaScript and CSS contexts have different rules. This tool is not a sanitizer or general XSS protection.
What happens to text that already contains an entity?
Its ampersand is encoded again, so < becomes &lt;. The Decoder turns that back into < in one pass.
Related Tools
HTML Decoder
Decode a limited set of HTML references: &, <, >, " and '. Unknown, malformed and other numeric references are left unchanged.
HTML Formatter and Minifier
Indent markup for readability or reduce whitespace between tokens. This formatter/minifier transforms text; it does not parse or validate HTML.