Secrets and encoding

How to escape HTML before you display user text

Escape characters such as <, > and & before inserting untrusted text into an HTML text context. PageUtil HTML Escape produces the escaped representation. HTML escaping is context-specific; it does not replace the handling required for JavaScript, CSS or URL values.

URL encoding, percent-decoding, and HTML escaping are different jobs.
HTML escaping is for element text, and it is a different job from encoding a URL.

What to run

Open HTML Escape. It stays in the browser.

How to read the result

< becomes &lt;. & becomes &amp;.

That is safe to put in element text.

It is not safe inside a URL attribute by itself, and it is not a sanitiser for a whole HTML document.

What to open next

For href values, parse and validate the permitted URL scheme and destination, encode component values as needed, and escape the final HTML attribute. URL encoding alone does not make a javascript: URL safe. Prefer safe DOM APIs for untrusted text.

Open Graph Generator already emits escaped tags if you use its snippet. It stays in the browser.

References

Related tools

Frequently asked questions

What does HTML escaping change in user text?

< becomes &lt; and & becomes &amp;. That is safe to put in element text.

Is escaped text safe inside a URL attribute?

It is not safe inside a URL attribute by itself, and it is not a sanitiser for a whole HTML document. HTML escaping is for element text.

Is HTML escaping the same job as encoding a URL?

HTML escaping is for element text, and it is a different job from encoding a URL. HTML Escape stays in the browser.

Need help with a tool or found a bug?

Report an issue directly to engineering. No accounts required — all client data remains private on your device.

Report an Issue →