HTML Entity Encode — Encode Text to HTML Entities
Encode special characters to HTML entities (&, <, >, ©). Runs entirely in your browser. No uploads, no limits.
HTML entity encoding is the inverse of decoding: turning characters that have special meaning in HTML markup (or that are awkward to type on a keyboard) into the entity syntax that any HTML parser recognizes. The two characters that absolutely must be encoded in HTML content are <, >, and & — the angle brackets that delimit tags and the ampersand that introduces entities. Without encoding them, an HTML parser interprets them as markup rather than content, and a string like if a < b && b < c becomes a broken page. Encoding is what makes the string safe to embed in HTML.
The choice between named, numeric decimal, and numeric hex is mostly a style preference, but there are practical differences. Named entities (&, ©) are the most readable form and the one HTML authors wrote by hand in the 1990s. Numeric entities (&, &) are universal — they cover every Unicode character, not just the 2,000-ish named ones. Numeric hex is the most compact for high code points (an emoji at U+1F600 is 😀 decimal or 😀 hex). For the narrow case of inserting text into an HTML attribute, the HTML-safe-only mode encodes only the five characters that can break attribute quoting (<, >, &, \", ') and leaves everything else as raw UTF-8, which keeps the output legible.
For a final hand-off: if the destination is an HTML document or an HTML fragment inside another document, any of the three modes works. If the destination is a JSON string that contains HTML (common in CMS APIs and rich-text editors), encode the HTML first, then JSON-escape the whole string. If the destination is JavaScript source code or a CSS file, HTML entities do not apply — use a JavaScript-string or CSS-string escape instead. The encoder here is HTML-only by design, and the right tool for the right context saves a layer of debugging.
How to use
Type or paste the text
Drop the text into the input area. The encoder leaves ASCII letters and digits untouched — only characters with HTML entity equivalents are encoded, keeping the output readable.
Pick an encoding mode
Default is named entities (`&`, `©`). Switch to numeric decimal (`&`), numeric hex (`&`), or HTML-safe-only (encode only `<`, `>`, `&`, `"`, `'`) for cases where the output goes into an attribute value.
Copy or download the result
Copy the entity-encoded text to your clipboard, or download it as a .html file. The encoder preserves all whitespace from the input — round-trip the output through the decoder to verify.
Frequently asked
Which characters should be encoded?
Always encode `<`, `>`, and `&` in HTML content (they have markup meaning). In attribute values, also encode `"` and `'` to avoid breaking the quoting. Other characters with named entities (copyright, em-dash, smart quotes) can be encoded or pasted as raw UTF-8 — modern browsers render both correctly.
What is the difference between named and numeric entities?
Named entities use mnemonics like `&` and `©`; numeric entities use the code point in decimal (`&`) or hexadecimal (`&`). Both decode to the same character. Named entities are more readable but limited to about 2,000 entries; numeric entities cover every Unicode character including emoji and rare scripts.
Does the encoder double-encode existing entities?
Yes — the encoder treats input as plain text. If the input already contains `&`, the encoder produces `&amp;`. Run the input through the decoder first if it is already partially encoded, or use the HTML-safe-only mode if you only need to escape the markup-significant characters.
Will the output work in CSS or JavaScript?
CSS uses a different escape syntax (backslash followed by hex code, like `\26 `). JavaScript uses `\u0026` for hex or `\x26` for short hex. HTML entities only work in HTML content. For JavaScript or CSS contexts, use a tool that emits the language-specific escape.
Is the encoding reversible?
Yes — the encoder is fully reversible by the decoder. Round-trip any input through the encoder then the decoder and the original characters come back. The only loss is when the input contains characters that have no entity form (very rare — almost every Unicode character has at least a numeric entity).
Limitations
- No double-encoding detectionThe encoder treats all input as plain text. An input of `&` encodes to `&amp;`, which decodes to `&` — not to `&`. Decode the input first if you suspect pre-encoded content.
- ASCII letters are not encodedThe default mode leaves ASCII letters and digits untouched. Encoding every character produces output that is hard to read and inflates file size without security benefit — most HTML bodies work fine with only `<`, `>`, `&`, `"`, `'` escaped.
- Not for CSS or JavaScriptHTML entities do not work in CSS or JavaScript contexts. CSS uses `\26 ` (backslash-hex), JavaScript uses `\u0026`. Encoding for those contexts requires a different tool or a language-aware escape.
Platform notes
- macOS
- TextEdit does not auto-encode on save. The browser tool is the right pick for text pasted into HTML fields where `<` and `>` would otherwise be parsed as markup, breaking the rendered output.
- Windows
- Notepad and VS Code save HTML as raw UTF-8 by default. The browser tool is the right pick when the destination is an HTML attribute value or a CMS field that requires entities rather than raw characters.
- Linux
- For command-line work, `python3 -c 'import html; print(html.escape(s))'` is the closest equivalent. The browser tool is the right pick for text pasted from a chat, an email, or a documentation page where retyping into a Python REPL is impractical.
- Web
- Runs entirely client-side. Works offline once the page has loaded. The encoded output is portable HTML — paste it into any web page, CMS field, or HTML attribute without depending on the destination's encoding handling.