What HTML Encoding Actually Does
HTML encoding converts markup into a representation that is safe to embed in other contexts — inside a JavaScript string, a CSS rule, an XML document, or a data URI. It is a transport transformation, not security. Every method here is trivially reversible, because the browser has to decode it to render the page.
This tool gives you five encoding methods so you can match the target context:
The Five Encoding Methods
| Method | Output | Needs JS? | SEO-Safe? | Best For |
|---|---|---|---|---|
| Base64 | <script>document.write(atob("..."))</script> | Yes | No | Embedding HTML in a string or data attribute |
| Hexadecimal | <script>document.write(String.fromCharCode(0x3C,...))</script> | Yes | No | Byte-level transport, escaping special chars |
| HTML Entities | <h1>Hello</h1> | No | ✅ Yes | CMS fields, XML, anywhere raw HTML is stripped |
| Unicode Escape | <script>document.write("\u003C\u0068...")</script> | Yes | No | JavaScript string contexts, JSON-adjacent |
| JS Self-Decoding | Character codes + String.fromCharCode | Yes | No | Fully self-contained snippet that runs anywhere |
Which Method Should You Use?
| Goal | Recommended Method |
|---|---|
| Embed HTML inside a JS string | Base64 |
| Embed HTML in XML or an attribute | HTML Entities |
| Keep SEO and no-JS compatibility | HTML Entities (only method that works without JS) |
| Send HTML through a JSON field | Base64 or Unicode Escape |
| Encode only emails / phone numbers | HTML Entities + Email/Phone toggles |
Important Caveats
document.write at parse time. If JavaScript is disabled, blocked by Content-Security-Policy, or the user is a crawler that doesn't execute JS, the page will render blank. Only HTML Entities works without JavaScript.
What HTML Encoding Cannot Do
- It cannot protect secrets. Anything rendered in the browser is visible in DevTools regardless of encoding.
- It cannot stop scrapers that run JavaScript. Headless Chrome and Puppeteer see the decoded DOM.
- It cannot replace server-side authentication. Encoding a login form does not make it secure.
- It cannot improve performance. Every method here makes the file larger, not smaller.
Encoding vs Obfuscation vs Encryption
| Encoding | Obfuscation | Encryption | |
|---|---|---|---|
| Goal | Safe transport | Harder to read | Confidentiality |
| Reversible? | Trivially | Trivially, with effort | Only with key |
| Needs key? | No | No | Yes |
| What this tool does | ✅ | ❌ | ❌ |
If you actually want to obfuscate JavaScript, use the JS AST Obfuscator. If you want to obfuscate CSS class names, use the CSS Class Obfuscator. HTML encoding is a different problem with a different solution.
Frequently Asked Questions
Is HTML encoding secure?
Does HTML encoding hurt SEO?
Can I still style and script my page normally?
Does encoding break forms or interactive elements?
document.write at parse time, so the resulting DOM is identical. However, any inline event handlers or inline scripts inside the encoded HTML must also survive encoding.Why does my page go blank after encoding?
<html> document but pasted the output into a template that also wraps it, (3) the output was truncated, (4) the content contains characters that break the JS string.Can I encode only part of a page?
Does encoding affect email or phone links?
@ or digit patterns. They do not change mailto: or tel: hrefs — if those are present, they remain in the source.Is my HTML uploaded to your server?
Can I download the output as a file?
encoded.html.Which method is hardest to reverse?
String.fromCharCode over an array — one line in the console to decode.Can I decode the output back to HTML?
Related Tools
External Resources
- MDN: Window.btoa() — Base64 encoding reference
- MDN: Window.atob() — Base64 decoding reference
- MDN: HTML Entities — character reference documentation
- MDN: String.fromCharCode() — used by hex and JS self-decoding methods
- WHATWG HTML Parsing Spec — how browsers parse HTML
- OWASP Top Ten — why encoding is not a security control