HTML Entities and Escaping

Updated 2026-09-10 · 3 min read

What HTML escaping does

HTML escaping turns special characters into entities so the browser displays them as text instead of interpreting them as markup. For example, < becomes &lt; and & becomes &amp;.

Characters you usually need to encode

The exact set depends on where the text is placed, but these five characters are the safest baseline when text will appear inside HTML content or attributes.

Escaping helps prevent XSS

If user input is inserted into a page as raw HTML, an attacker can try to add tags or event handlers that run JavaScript. Escaping neutralizes that input for display. It does not replace validation, content security policy, safe templating, or careful handling of URLs, but it is one of the basic layers that keeps text from becoming code.

Encoding vs decoding

Encode before displaying untrusted text in HTML. Decode only when you intentionally need to read already-encoded text, such as an exported CMS field, email template, or source snippet. Do not decode user input and then inject it as HTML unless it has been sanitized for the exact context.

Use the encoder

Open the HTML Encoder and Decoder, paste your text, then encode or decode entities instantly. It runs in your browser and is useful for templates, snippets, support replies, CMS fields, and debugging copied HTML source.

Try the HTML Encoder / Decoder →Encode HTML entities (&, <, >, ", ') or decode them back to text. Free online HTML escape tool, instant and browser-based.

Frequently asked questions

Is escaping the same as sanitizing HTML?

No. Escaping displays everything as text. Sanitizing tries to allow safe HTML while removing unsafe tags and attributes.

Should I escape text before saving it?

Usually no. Store the original text, then escape it at output time for the place where it will be displayed.

Does escaping make URLs safe?

Not by itself. URLs need their own validation and encoding rules, especially for query parameters and redirects.

More guides

How to Convert JSON to CSVConvert JSON arrays and objects into CSV for spreadsheets, databases, and reports, including headers, nested values, and escaping rules.URL Encoding Query ParametersLearn why URLs need percent encoding, which characters break query strings, and when to use encodeURIComponent instead of encodeURI.How to Validate JSON and Fix Common Syntax ErrorsLearn how to validate JSON and fix the most common errors: trailing commas, single quotes, unquoted keys, comments and unescaped characters — with examples.Base64 Is Not Encryption: What It Actually DoesBase64 is reversible encoding, not encryption. Learn what Base64 is for, when to use it, its 33% size cost, and safe alternatives for protecting data.