Web Developer Tools · · 4 min read
How to HTML Encode Text
Use the HTML Encode tool to escape &, <, >, ", and ' as HTML entities so text renders safely instead of breaking markup — in your browser.
To HTML encode text, open HTML Encode and paste your text into the input — it instantly escapes &, <, >, ", and ' as HTML entities, with an optional toggle to also encode every non-ASCII character.
What HTML Encode does
Browsers treat <, >, and & as the start of markup, not literal text, so dropping raw user input — a name with an apostrophe, a comment with a <, a title with an ampersand — straight into HTML can break the page's structure or, worse, let someone inject their own tags. HTML entity encoding replaces each of these characters with a named or numeric escape sequence (&, <, and so on) that browsers render back as the original character, so the text displays correctly without being interpreted as markup. Toolbench's HTML Encode tool does exactly that, with one extra setting: Encode non-ASCII too, which also converts every character outside the basic ASCII range into a numeric entity.
How to HTML encode text with Toolbench
- Open HTML Encode.
- Paste or type your text into the input panel.
- Read the escaped output — it updates as you type.
- Turn on Encode non-ASCII too if you want accented letters, emoji, or other non-ASCII characters converted into numeric entities as well.
- Click Copy to copy the result, or use Send to → to pass it straight into another tool.
Encode non-ASCII too defaults to off, meaning only &, <, >, ", and ' get escaped.
A real worked example
With the default settings, this input:
<a href="/?q=1&x=2">Tom & Jerry</a>
produces:
<a href="/?q=1&x=2">Tom & Jerry</a>
Every <, >, ", and & is escaped, so if you dropped this string into an HTML page it would display as the literal text <a href="/?q=1&x=2">Tom & Jerry</a> instead of being rendered as a clickable link.
What the non-ASCII toggle changes
By default, only the five characters that are unsafe in HTML (&, <, >, ", ') get escaped — everything else, including accented letters and emoji, passes through unchanged. Turning on Encode non-ASCII too adds a second pass that converts every character outside the ASCII range into a numeric entity using its Unicode code point. This input:
Café — naïve, 100% ✅
stays exactly as written with the toggle off, but becomes:
Café — naïve, 100% ✅
with it on. Both versions render identically in a browser — the toggle is only useful if you need output that's restricted to plain ASCII characters, such as for older systems or strict text encodings.
Reference: what each setting does
| Setting | Default | Effect |
|---|---|---|
| Encode non-ASCII too | Off | When off, only & < > " ' are escaped. When on, every character outside ASCII is also converted to a numeric entity. |
Tips and common mistakes
- Escape user input before inserting it into HTML, not after. If you build a page by concatenating strings, encode each dynamic value before it goes into the markup — encoding the whole finished page afterward will escape your own tags too.
- You usually don't need the non-ASCII toggle. Modern browsers handle UTF-8 just fine; leave it off unless a specific system requires ASCII-only output.
- Encoding twice double-escapes your text. Running already-encoded text through the tool again turns
&into&amp;— if you see&repeated in your output, you've encoded more than once. - This only encodes — it doesn't sanitize. Escaping entities stops text from being interpreted as markup, but it isn't a substitute for a dedicated HTML sanitizer if you're rendering untrusted HTML rather than plain text.
- Nothing is sent to a server. Encoding happens in your browser as you type.
Related tools
- HTML Decode — convert HTML entities back into their original characters.
- URL Encode — percent-encode text for safe use inside a URL instead of HTML.
- Base64 / URL Encode — switch between Base64, URL percent-encoding, and HTML entity encoding in one tool.
- JavaScript Obfuscator — obscure JavaScript source instead of escaping markup characters.
Frequently asked questions
Which characters does HTML Encode escape by default?
&, <, >, ", and ' — the characters that have special meaning in HTML markup. Everything else, including letters, numbers, and non-ASCII characters, passes through unchanged unless you turn on Encode non-ASCII too.
Why would I turn on Encode non-ASCII too?
It's only needed when your destination requires pure ASCII output, such as an older system or a strict text format. The resulting numeric entities (like é for é) render identically to the original character in any browser, so most people can leave this off.
Does HTML encoding protect against XSS?
Escaping <, >, and & stops text from being parsed as new HTML tags, which closes off the most common injection path. But it's not a complete sanitizer — if you're rendering untrusted HTML (not just plain text) you still need a proper sanitization library.
What's the difference between HTML Encode and URL Encode?
HTML Encode escapes characters that would otherwise be interpreted as markup inside an HTML page. URL Encode percent-encodes characters that aren't safe inside a URL. Use whichever matches where the text is actually going.
Is my text sent to a server?
No. Encoding happens in your browser as you type. Signed-out visitors have nothing saved; if you're signed in, your input syncs privately to your account.
More guides
- How to Beautify and Format JavaScriptUse the JavaScript Beautifier to turn minified or messy JS into clean, indented code with 2-space, 4-space, or tab indentation.
- How to Minify CSS to Shrink Stylesheet File SizeUse the CSS Minifier to strip comments and whitespace from CSS instantly in your browser, with a real before-and-after example.
- How to Beautify and Format CSSUse the CSS Beautifier to turn minified or cramped CSS into clean, indented rules with 2-space, 4-space, or tab indentation.