Skip to content
Toolcroft

HTML Entity Encoder / Decoder

Encoding Tools

Encode HTML text or attribute characters as named, decimal, or hex entities, or decode references. Choose a character scope; processing stays in your browser.

Mode
Entity style
Characters to encode

Choose a scope for the output context. For URLs, JavaScript, or CSS, use an encoder made for that context.

How to use this tool

  1. Choose Encode or Decode. Select Encode to convert chosen characters into HTML references. Select Decode to expand recognized references back to readable text.
  2. Select the character scope and entity style. Choose Text-safe for &, <, and >; Attribute-safe also escapes quotes; All non-ASCII additionally encodes every character above U+007F. Select Named, Decimal, or Hex to choose the reference notation.
  3. Enter your text. Type or paste your input. The output updates instantly.
  4. Copy the result. Click the Copy button to copy the encoded or decoded text to your clipboard.

What are HTML entities?

HTML character references let source text represent characters that have special meaning in markup. A reference starts with & and usually ends with ;: for example, &lt; represents the less-than sign, and &amp; represents an ampersand. Numeric references use a Unicode code point, such as &#169; in decimal or &#xA9; in hexadecimal for ©. This encoder updates as you type and runs in your browser, so you can prepare a text snippet without sending the input to a server.

The default Text-safe scope escapes &, <, and > while leaving ordinary letters, punctuation, and Unicode characters as they are. This is useful when writing literal text inside an HTML text node, such as showing a code sample containing <section>. Attribute-safe mode also escapes both kinds of quotation marks. All non-ASCII mode additionally replaces characters above U+007F, which can help when a downstream system specifically requires ASCII-only source.

Choosing a scope and notation

Scope answers which characters to replace; entity style answers how each replacement is written. Named mode uses a curated set of common references such as &copy;, &eacute;, and &mdash;. If a character has no entry in that set, Named mode falls back to a hexadecimal numeric reference. Decimal and Hex modes use numeric references for every selected character. All three forms represent the same code point when the reference is recognized by an HTML parser.

For example, if a documentation author wants to show the literal text <h1>A & B</h1>, Text-safe mode escapes the ampersand and angle brackets but keeps the surrounding words readable. If an application exports ASCII-only markup containing café, All non-ASCII mode can represent é as a named reference, while an emoji without a curated name uses its numeric code point. The output summary reports character counts, UTF-8 byte counts, and the change in text length.

Decoding and its limits

Decode mode expands known semicolon-terminated named references and valid decimal or hexadecimal numeric references. It works on plain text: raw tags such as <strong>hello</strong> stay intact, unknown entity names are left unchanged, and double-encoded input is decoded one layer at a time. The named table is a practical subset rather than the complete HTML5 character-reference list, and Decode does not implement every parsing rule used by browsers.

Use context-aware output handling

HTML entity encoding is not a general-purpose sanitizer or a complete XSS defense. The right escaping depends on where data goes: HTML text, a quoted attribute, a URL, JavaScript, and CSS each have different rules. For production applications, use a template system that escapes for the output context and avoid inserting untrusted strings as markup. A Content Security Policy can add defense in depth, but it does not replace correct output handling. This browser tool is intended for inspecting and preparing text, not auditing an application’s security.

Frequently asked questions

What are HTML entities?

HTML entities are sequences of characters used to represent characters that have special meaning in HTML, or that cannot easily be typed. For example, the less-than sign (<) must be written as &lt; in HTML source so the browser does not interpret it as a tag.

What is the difference between named, decimal, and hex entities?

Named entities use a mnemonic such as &amp;, &copy;, or &eacute;. Decimal numeric entities use the Unicode code point in base 10 (&#38; for &). Hex numeric entities use the code point in hexadecimal (&#x26; for &). This tool uses a curated common-name table and falls back to numeric references for other characters in All non-ASCII mode.

Which characters should I encode?

For literal HTML text, escape &, <, and >. For a quoted HTML attribute, also escape both quote characters. Choose All non-ASCII when an ASCII-only source is required. HTML encoding is context-specific: it does not replace URL, JavaScript, or CSS encoding, or a template engine that safely escapes output.

Does Decode parse HTML tags or every HTML5 entity?

No. Decode expands recognized semicolon-terminated named references and valid decimal or hexadecimal numeric references. Raw tags and unknown names remain unchanged. The decoder does not implement the full HTML5 tokenizer and is not an HTML sanitizer.

Can I safely insert decoded output into a web page?

Decoding restores characters such as < and &, so decoded output can contain markup-significant text. Treat the result as untrusted input and use context-aware escaping or safe DOM text APIs before putting it in a page. This tool does not sanitize HTML or assess XSS risk.

Browse all encoding tools