HTML character references represent characters with forms such as &, ©, or 🙂. Use this tool to escape the characters that have structural meaning in HTML, or to decode named and numeric references into plain text.
Encoding and decoding run locally in your browser and update as you type. The result is displayed as text: the decoder does not render elements or execute scripts.
How to Use the HTML Entity Encoder and Decoder
Escape text for an HTML context or inspect a string containing character references.
- Choose Encode or Decode in the Mode control.
- In Encode mode, optionally select Also encode non-ASCII characters (
&#x…;). - Type or paste content into Text or HTML to encode, or switch modes and use Text with entities to decode.
- Read the result in Encoded output or Decoded text.
- Select Swap to move the output into the input and switch modes, or select Copy to copy the output.
HTML Character References and the Five Escaped Characters
HTML uses < and > around tags, & to begin a character reference, and quotation marks around many attribute values. When those characters belong to data rather than markup, escaping prevents the parser from treating them as structure in the relevant context.
Encode mode replaces five characters: & becomes &, < becomes <, > becomes >, " becomes ", and ' becomes '. It processes ampersands first as part of the same replacement pass, so existing reference-looking text is escaped as literal text rather than preserved as an entity.
Fish & Chips < 10
This five-character set is useful for ordinary HTML text and quoted attribute values, but context still matters. HTML, URLs, CSS, and JavaScript embedded in a page have different grammars. Do not use HTML entity encoding as a universal substitute for URL encoding, JavaScript string escaping, or a framework’s context-aware output handling.
For percent-encoded URL components, use the URL encoder and decoder. For backslash-based source strings, use the backslash escape and unescape tool.
Named, Decimal, and Hexadecimal References
A named reference uses a standardized name such as ©. A decimal numeric reference uses a code point number such as ©, while a hexadecimal numeric reference writes the number in base 16, as in ©. These three examples represent the copyright sign.
When Also encode non-ASCII characters (&#x…;) is selected, the encoder first escapes the five HTML-sensitive characters and then converts each character outside ASCII to an uppercase hexadecimal numeric reference. It works by Unicode code point, so a supplementary character such as an emoji becomes one reference rather than two UTF-16 surrogate references.
Without that checkbox, non-ASCII text remains literal Unicode. Modern UTF-8 HTML normally supports that representation directly and is often easier to read. Numeric references are useful when an interface requires ASCII-only text, but they do not change the underlying character represented by the browser.
Decode mode uses the browser’s HTML parser through a detached textarea. It can resolve the named and numeric character references recognized by that parser, including some legacy forms where HTML parsing permits a missing semicolon. The tool does not maintain its own fixed entity table.
Double Encoding, Invalid References, and Round Trips
Double encoding occurs when already escaped text is encoded again. For example, < becomes &lt;, so one decoding pass produces < rather than <. This behavior is intentional for an encoder that treats its input as literal text. Decide whether your source is raw text or previously encoded markup before applying another pass.
Decoding is not a lossless way to preserve source spelling. ©, ©, and © decode to the same character, and subsequent encoding may choose a different representation. Entity-name capitalization, optional semicolons, and the original numeric base are not retained.
Unknown or malformed sequences are handled according to the browser’s HTML parsing rules and may remain partially or entirely literal. The status count is a convenience based on reference-looking patterns in the input or output; it is not a conformance report. Use a validator when exact HTML syntax matters.
Character references also cannot repair text that was decoded with the wrong character encoding. Mojibake such as Français usually indicates a UTF-8 or legacy-encoding mismatch, not missing HTML entities. Fix the byte-to-text decoding step before adding character references.
Security, XSS, and Local Processing
The transformation happens in the browser, and the implementation makes no network call with the input. Decoded output goes into a readonly textarea. Even if <script> becomes <script>, this page treats those characters as text and does not create or run a script element.
The copied result can still be unsafe in another context. Decoding untrusted content and assigning it to innerHTML can turn harmless-looking references into active markup. Conversely, encoding only the five basic characters is not a complete sanitizer for every HTML location; URL attributes, CSS, JavaScript, and unquoted attributes require context-specific handling and validation.
Prefer a framework’s automatic escaping for normal template output, and use a maintained sanitizer when users are allowed to submit a limited HTML subset. Avoid decoding just to insert the result as markup. The safer architecture is to keep data as text and use APIs such as textContent unless trusted HTML is genuinely required.
Entity encoding is reversible and provides no secrecy. Redact credentials, personal information, and private markup before sharing an encoded value. If you need to inspect the resulting markup without treating formatting as sanitization, use the HTML beautifier.
Frequently Asked Questions
Which characters does Encode escape by default?
It escapes ampersand, less-than, greater-than, double quote, and apostrophe. The apostrophe becomes ', while the other four use &, <, >, and ". Other ASCII and non-ASCII characters remain unchanged unless the non-ASCII option is selected.
What does Also encode non-ASCII characters do?
It converts each non-ASCII Unicode code point to an uppercase hexadecimal numeric reference such as é. It does not transliterate characters or convert them to approximate ASCII letters. The five HTML-sensitive characters are still escaped in their normal forms.
Can the decoder handle named and numeric entities?
It uses the browser’s HTML parser, so it handles named references and decimal or hexadecimal numeric references recognized by that parser. Parsing rules for malformed input and omitted semicolons are context-sensitive. The tool does not claim that every entity-like sequence is valid.
Why did my entity become double encoded?
Encode mode treats the entire input as literal text, including the ampersand at the start of an existing entity. Thus < becomes &lt;. Decode once first only if the input is genuinely an encoded value and you intend to work with its character result.
Does entity encoding prevent cross-site scripting?
Correct output encoding is one part of XSS prevention, but it must match the destination context. This encoder covers ordinary HTML-sensitive characters; it does not sanitize allowed markup or validate URL, CSS, and JavaScript contexts. Keep framework auto-escaping enabled and use a dedicated sanitizer for untrusted HTML.
References: WHATWG HTML Standard: Named character references · MDN: Character reference.