b2KIT

HTML Entity Encoder / Decoder

Convert special characters to HTML entities and decode HTML entities back to their original characters.

Tested tool guide Tested browser tools Checked August 16, 2026

What HTML Entity Encoder / Decoder does, with a checked example

Literal ampersands and angle brackets can collide with HTML syntax. This converter has two directions: Encode replaces those characters with HTML character references, while Decode restores references such as `&amp;` and `&lt;` to `&` and `<`. It is useful for preparing a text fragment for HTML source or inspecting text copied from encoded markup. The encoded result is intentionally more verbose than the displayed text. The easy mistake is treating decoding as sanitization. Decoded angle brackets may form tags when the result is later inserted into an HTML document.

Worked example

A concrete input and expected output from the current implementation.

Input

Fish & Chips

Expected output

Fish &amp; Chips

With Encode selected, the literal ampersand is written as the named HTML character reference `&amp;`. The letters and spaces do not require replacement in ordinary HTML text.

How the result is produced

1

Encoding text

In Encode mode, the input is treated as text and characters with special meaning in HTML are written as references. A literal ampersand is represented by `&amp;`; a less-than sign can be represented by `&lt;`. The output is source notation, so its references normally display as the original characters when parsed in an appropriate HTML text context.

2

Decoding references

In Decode mode, a recognized reference is replaced by the character it denotes. `&amp;` produces one ampersand rather than the five visible source characters in the reference. Decode changes the text itself; it does not merely alter a preview. If the result contains markup-significant characters, their later interpretation depends on where the user places that result.

Good uses

  • Preparing a product title such as `Tea & Biscuits` for inclusion as literal text inside a hand-written HTML element without leaving a bare ampersand.
  • Decoding `&lt;section&gt;` from a CMS export, email source, or copied code sample to recover the underlying `<section>` text.
  • Checking whether a display bug comes from encoded source, such as seeing `&amp;` on screen where a single ampersand was intended.

Limits and checks

  • HTML entity encoding is not interchangeable with URL percent-encoding, JSON string escaping, JavaScript escaping, or CSS escaping. Those formats assign different meanings to punctuation.
  • Decoded output can contain markup. The conversion neither removes tags nor determines whether they are safe, so untrusted decoded text should not be inserted as HTML.
  • Decode discards the distinction between a reference and its represented character. After `&amp;` becomes `&`, the result alone cannot reveal how that ampersand was originally written.

Common questions

Will encoding make arbitrary input safe everywhere in an HTML page?

No. Safety depends on the destination context. Element text, quoted attributes, unquoted attributes, script content, style content, and URLs do not all follow the same parsing rules. Use the escaping mechanism appropriate to the exact insertion context. Decode provides no safety guarantee and can expose `<` or `>` characters that were previously represented as text.

Why does `&amp;` still appear literally on my web page?

An HTML parser normally interprets `&amp;` in source as an ampersand for display. If the reference itself appears, it may have been encoded again or inserted through a text-only operation that intentionally displays markup characters literally. Inspect the actual stored value and insertion context; repeatedly decoding until the page looks right can alter text that was meant to remain encoded.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools