Writing user-supplied text directly into an HTML page is one of the oldest bugs in web development, and it has two faces: the annoying face where a search result containing a quotation mark silently truncates your attribute, and the dangerous face where a cleverly crafted input becomes executable script in someone else's browser. HTML encoding is the fix for both. This tool converts the five characters that matter most, the ampersand, the angle brackets, and both quotation marks, into their safe entity forms, live as you type.
Paste or type any text into the input panel and the encoded result appears immediately beside it. Everything runs locally in your browser: no text is uploaded, no account is needed, and the page works offline once loaded. That matters because the text you most need to encode, form input, comments, and content containing names or messages, is often exactly the content you should not be sending anywhere unnecessarily.
The tool uses the compact entity set that modern standards recommend: & becomes &, < becomes the less-than escape, > becomes the greater-than escape, " becomes the double-quote escape, and ' becomes the apostrophe escape. Characters that are already safe in HTML, such as letters, digits, and common punctuation, pass through untouched, so encoded text stays short and readable.
Which Characters Get Encoded and Why?
HTML has exactly five characters with syntactic meaning inside ordinary text and attribute contexts. The ampersand starts an entity, the less-than sign starts a tag, the greater-than sign ends one, the double quote delimits attribute values written with double quotes, and the apostrophe delimits values written with single quotes. Leave any of them raw and the browser may interpret structure where you meant text.
| Character | Encoded form | Risk if left raw |
|---|---|---|
| & | & | Starts a bogus entity; a raw ampersand followed by letters can be swallowed or mis-rendered |
| < | the less-than escape &lt; | Opens a tag; a raw < turns everything after it into markup until the next > |
| > | the greater-than escape &gt; | Closes an unintended tag or completes a fragment an attacker opened elsewhere |
| " | the double-quote escape &quot; | Ends a double-quoted attribute early; the rest of the value becomes attributes or markup |
| ' | the apostrophe escape &#39; | Ends a single-quoted attribute early, same class of breakage |
A concrete attribute example shows why the quotes matter. Suppose you render a nickname into an input field: a value containing a double quote, such as a craft store name with inches in it, like 12" vinyl, will end the value attribute at the quote. Everything after it, in this case the word vinyl, becomes stray attributes on the input element, and the field displays only 12. Encode the value first and the full string survives the trip into the page and back out again.
The Encoding-Prevents-XSS Angle
Cross-site scripting, usually abbreviated XSS, happens when untrusted text reaches the browser in a context where it is treated as code rather than as data. The classic payload is a comment field that contains a script tag. If the server stores the raw text and every later visitor's browser receives it as real markup, the script runs in each visitor's session, with access to their cookies and page content. Contextual output encoding breaks this attack: the same payload, encoded, renders as visible text that reads like a failed exploit instead of executing as one.
Encoding is one layer of a defense-in-depth approach, and honesty about scope matters. Encoding the five core characters protects text nodes and quoted attribute values, which covers the majority of injection points in a typical page. It does not protect other contexts: a value dropped into a JavaScript string literal, a URL, or a CSS property needs escaping rules specific to that context, because those contexts have their own special characters. When you build pages, encode at the moment of output, with a function intended for the HTML context, rather than trying to sanitize once at input time and hoping the value is only ever used in one place.
Trying this tool on a known payload is instructive. Take the fragment that starts with a less-than sign and the word script. After one pass through the encoder, the angle brackets are gone, replaced by their escape sequences, and the ampersands inside the escapes are themselves escaped, so the output is inert text no matter where you embed it. Pasting the result back into an HTML page renders visible text, not an executable element.
How to Use the Encoder (Step by Step)
- Paste the text or HTML fragment you need to make safe into the input area. Encoding runs live; there is no button to click.
- Check the output panel. Safe characters pass through unchanged, so the result stays compact and easy to eyeball.
- Copy the encoded string with the copy button and place it wherever the raw version would have been dangerous: an attribute value, a stored field that will later be rendered, or a generated HTML fragment.
- If you need the reverse operation, use the paired decode tool on this site; encoding and decoding are exact inverses of each other.
One caution applies in the other direction. If your source text already contains entities you wrote deliberately, such as a literal ampersand followed by the letters nbsp, the encoder will escape the ampersand again, producing a doubly-encoded string that displays as visible entity text when rendered. Encode plain text, not text that has already been through an encoder.
When to Encode Quotes Specifically
The question of when the quotation marks need encoding comes up constantly, and the answer depends on where the text will land. Inside ordinary paragraph text, quotes are harmless; browsers do not start attributes in text nodes. The moment your text is destined for any attribute value, both quote characters must be encoded, because you cannot control which quoting style the surrounding markup uses. A single unencoded apostrophe inside a single-quoted attribute ends the attribute exactly where the apostrophe sits.
There is a subtler reason to encode quotes even in text contexts: consistency and pipelines. If some content flows into attributes and some into text nodes depending on data you do not fully control, encoding all five characters everywhere is the simplest policy that is always correct. The cost is a few extra bytes per quote; a page with one hundred apostrophes spends roughly five hundred extra bytes, which server compression reduces to well under a hundred. That price buys a pipeline where the same escaping rule applies to every string, with no case analysis that a future edit can get wrong.
Encode, Decode, and Round-Trip Behavior
Encoding followed by decoding is lossless. Take a sample like Jane said "check the 5x7 frames" and let her see. After encoding, every quote and ampersand is escaped; after decoding with the paired tool, the original string returns byte for byte. The same holds for text containing full markup, provided the markup was plain text in your mind rather than live markup: encoding turns markup into visible text, which is precisely the behavior you want for displaying code examples, showing template syntax in documentation, or rendering user comments verbatim.
The relationship between the two directions is worth internalizing because it defines the boundary of each tool. Encode when data is on its way to becoming part of an HTML document. Decode when escaped text has arrived from storage, an export, or a third party and you need to read the original. Running the wrong direction produces either entity soup or, worse, live markup where you expected inert text.
Tips and Best Practices
- Encode at output time, not input time. A value stored raw can be re-escaped correctly for each context it later appears in; a value stored pre-escaped is stuck with one context forever.
- Encode all five characters whenever text goes into any attribute, regardless of the quote style used, to make the rule context-independent.
- Spot-check encoded output for double escaping: the sequence for ampersand appearing twice in a row usually means the text was already escaped.
- For displaying code snippets on a page, encode the whole snippet; the angle-bracket escapes render as literal brackets and nothing executes.
- Remember that attribute contexts with special syntax, such as URLs and inline event handlers, need additional care beyond the five core characters.
- When testing an escaping fix, include the worst-case sample: an apostrophe, a double quote, an ampersand, and an angle bracket in one string.