Encoding and escaping

HTML entity encoderwith one-pass decoding

with one-pass decoding

HTML entity encoder

Current text

Encode turns source text into entities; decode turns entities back into text, one layer at a time. Format, preservation and decode context affect only the next action. A failure keeps the current text.

Ctrl/Cmd+Enter: Encode textCtrl/Cmd+Shift+Enter: Decode entities

Enter text or load an example. Empty input converts to empty output.

0 UTF-16 units

Conversion options

Format and preservation affect the next encode; decode context affects the next decode. Neither rewrites the current text. Encoding preserves U+0020–U+007E plus TAB, CR and LF except &, <, >, both quotes and backtick. Disable preservation to encode everything. Decoding resolves one HTML5 layer; unknown references remain. Numeric invalid values and C1 follow HTML replacements.

First input: 1,048,576 UTF-16 units. Output and later processing of a generated document: 4,194,304 units. Empty input is valid. Pasting may normalize line endings.

View original

Conversion stays in this browser; input is not uploaded. Undo history stays in this tab. Long documents limit how much history is kept.

The HTML entity encoder helps when a code example must display angle brackets or when a CMS value arrives as character references. Choose readable names or numeric HTML entities according to the receiving format.

An HTML entity decoder restores references without parsing a document. HTML escape changes the representation of characters; it does not decide whether a complete template, script or URL is safe.

Why use this HTML entity encoder?

Compare three representations

This HTML entity encoder offers named references, decimal numbers and uppercase hexadecimal numbers. A missing name falls back to hexadecimal, so symbols outside the named table can still be represented.

Three entity representations converge on the same symbol.

Read markup without running it

Decoded angle brackets remain visible text in the result and preview. A tag-shaped value never becomes a live page here, letting you inspect copied examples without creating document elements.

A read-only document keeps markup symbols as plain text.

Choose the context before checking the result

01

Keep ordinary text readable

Encoding starts with named references and basic text preserved: printable ASCII plus TAB, CR and LF. The six characters &, <, >, both quotes and the backtick are always encoded; non-ASCII is encoded too.

02

Convert only when you choose

Nothing runs automatically. Click Encode text or Decode entities, or press Ctrl/Cmd+Enter to encode and Ctrl/Cmd+Shift+Enter to decode. Options affect only the next action. A failure keeps the current text and does not add a successful history step.

03

The editor holds the full text

Example and Clear start a new document and can be undone. Undo and redo cover edits, conversions, restoring the original, examples and clearing. Copy and download export the full current text. The plain-text preview matches only the latest successful conversion, shows at most 20,000 UTF-16 units, never executes tags, and is not the document.

Character references with explicit choices

HTML5 names

The complete HTML5 named-reference table includes symbols beyond the familiar &amp; and &lt;. Decimal and hexadecimal references are supported in the same decode input. Named HTML5 references may represent two code points together, such as fj becoming &fjlig; when all text is encoded.

Text or attribute context

The default is text context. Attribute context changes how legacy names without a semicolon are recognized, especially before an ASCII letter, digit or equals sign.

One layer per conversion

Decoding &amp;lt; produces &lt;, not a less-than sign. Unknown references remain unchanged. Each run resolves references in the input once.

Locate invalid source text

A raw NUL or isolated UTF-16 surrogate is rejected with a line and column. Numeric references to invalid code points follow HTML replacement rules instead of source-text validation.

Exact scope and conversion boundaries

Preservation has a defined range
Preserve basic text keeps U+0020–U+007E plus TAB, CR and LF, except &, <, >, single quote, double quote and backtick. Turn it off to encode every character. Existing ampersands are encoded again.
HTML recovery rules apply
Numeric references for zero, surrogates or values above U+10FFFF become U+FFFD. C1 numeric references use historical HTML replacements; an encoded raw C1 control may therefore decode differently.
No recursive decoding
Each run decodes one layer using the chosen text or attribute context. Some legacy names work without semicolons; recognition is context-dependent. Unknown references are retained. To decode another layer, click Decode again on the current text. Encode and decode stay separate and do not switch direction by themselves.
Plain text is not sanitization
No HTML document is parsed, rendered or sanitized. Entity conversion does not validate JavaScript, CSS, URLs or attribute placement, and it is not a complete XSS defense. XML entity rules are a separate task; this page uses HTML5 rules.
Source text and editor limits
Raw NUL and isolated UTF-16 surrogates fail in either direction. No Unicode normalization is performed. Pasting into the editor may normalize line endings before conversion.
Full results within fixed limits
The first input is limited to 1,048,576 UTF-16 units. Output and further processing of a generated document are limited to 4,194,304. Oversized output fails as a whole. Empty input is valid; there is no file import, network fetching or recursive mode.

HTML entity encoder questions

When should I encode HTML entities?

Use the HTML entity encoder when literal text such as <article> should be represented by character references. Match the escaping method to the destination context; this page handles characters, not complete document security.

What does unescape HTML mean?

It means replacing recognized character references with their characters: &amp; becomes & and &#60; becomes <. Here this happens once and the result remains plain text.

Does encoding HTML entities prevent XSS?

It can be one part of context-appropriate output escaping, but it is not a sanitizer or a general XSS guarantee. Script, style, URL and attribute contexts require their own handling.

What is the difference between named and numeric entities?

A name such as &copy; identifies a character through the HTML table. Decimal &#169; and hexadecimal &#xA9; identify its code point. Named encoding uses hexadecimal when no suitable name exists.

Why is &lt; still in the output?

The source may contain &amp;lt;, which has two encoding layers. One decode returns &lt;. Review that output before deliberately decoding it again; recursive decoding is not automatic.

Found an encoding edge case?

Try a short sample

Choose the HTML entity encoder format, inspect the plain-text result, and copy the complete value when it is current.