HandyTools Hub

HTML Encoder/Decoder

Encode or decode HTML entities. Fast, private, and easy to use.

Mode:

HTML encoding turns characters a browser would treat as markup into entity references that the browser displays literally. If you paste <strong>hello</strong> into a page as plain text, the browser sees a real bold tag; encode it first and the browser shows the tag itself. This tool encodes and decodes in both directions, with a safe mode for everyday escaping and a full mode that converts every non-ASCII character into a numeric reference. It is meant for developers, technical writers, and anyone who has to display code as text or clean up text that was escaped one too many times.

How to Use

  • Choose Encode or Decode at the top. The mode buttons swap the input placeholder and the label on the main action button so you can tell at a glance which direction is active.
  • In encode mode, pick Safe or Full. Safe escapes the five characters that can break markup; full additionally converts every character outside printable ASCII.
  • Paste or type into the left box. The output updates as you type, and the main button reprocesses using the current mode. A large paste is handled in the browser with no round trip.
  • Use Copy to put the result on the clipboard, or Download to save it as a text file named for the active direction. Clear empties both panes.

Safe Mode vs Full Mode

InputSafe modeFull mode
<p>café</p>&lt;p&gt;café&lt;/p&gt;&lt;p&gt;caf&#233;&lt;/p&gt;
He said "hi"He said &quot;hi&quot;He said &quot;hi&quot;
€100€100&#8364;100
A & BA &amp; BA &amp; B

Safe mode replaces exactly &, <, >, ", and ' (the apostrophe becomes &#39;). Full mode does the same, then replaces any remaining character whose code point is below U+0020 or above U+007E with a decimal numeric reference. Printable ASCII from space through ~ is left alone. Full mode is the right choice when the output must survive a page or system that does not declare UTF-8, when you are producing a file that has to be pure ASCII, or when invisible control characters need to be made visible. Safe mode keeps the text readable to humans, which is usually what you want when the destination is already UTF-8.

HTML Entities, Character References, and Code Points

HTML offers two ways to write a character that you cannot or do not want to type directly. A named entity such as &amp; or &lt; has a human-readable name and is easy to recognize. A numeric character reference writes the character’s Unicode code point, either in decimal (&#233;) or hexadecimal (&#xE9;). Both forms mean the same character to a browser. Full mode always emits decimal references because they are compact and unambiguous, and because decimal digits are readable ASCII. Knowing the code point is often the fastest way to decode a strange reference by hand: &#8364; is decimal 8364, which is U+20AC, the euro sign.

Worked Examples

  1. Encode <div class="box">Hi</div> in either mode gives &lt;div class=&quot;box&quot;&gt;Hi&lt;/div&gt;. Every character is printable ASCII apart from the five that are escaped, so safe and full agree.
  2. Encode Résumé & Co. gives Résumé &amp; Co. in safe mode and R&#233;sum&#233; &amp; Co. in full mode, because é is U+00E9, decimal 233.
  3. Encode a line containing a tab and the copyright sign in full mode. The tab (U+0009) becomes &#9; and the copyright sign (U+00A9) becomes &#169;, making both visible in the output.
  4. Decode &#x48;&#101;&#108;&#108;&#111; gives Hello, and decoding &lt;b&gt;bold&lt;/b&gt; gives <b>bold</b>.

How the Decoder Handles Entities

The decoder recognizes six named entities: &amp;, &lt;, &gt;, &quot;, &#39;, and &nbsp;. It also handles decimal references such as &#233; and hexadecimal references such as &#xE9; or &#XE9;. Anything else is passed through unchanged, so &copy;, &euro;, and malformed fragments stay exactly as written. One subtlety worth remembering: &nbsp; decodes to an ordinary space, not a non-breaking space, so a decoded paragraph can reflow differently than the original page. Round-tripping is therefore not always lossless.

Common Mistakes

  • Double encoding. Encoding &lt; again yields &amp;lt;, which the browser displays as the literal text &lt;. Decode first if you are unsure whether a string is already escaped.
  • Treating full mode as a security upgrade. Both modes escape the same five dangerous characters; full mode only changes how non-ASCII text is represented.
  • Assuming every named entity decodes. The decoder knows six names plus numeric forms, so &copy; and &euro; will surprise you.
  • Forgetting that full mode also escapes characters you may have wanted to keep, such as tabs, newlines, and the invisible control characters from a pasted document.
  • Placing an encoded value in an unquoted attribute. Always quote attribute values, because escaping alone does not make an unquoted attribute safe.

What HTML Encoding Does Not Do

Escaping the five characters prevents text from being read as markup, but it is not a sanitizer. It does not validate input, remove unwanted tags, or defuse dangerous URLs such as javascript:. If you need to render untrusted HTML rather than display it as text, pair escaping with a dedicated sanitizer. As a rule of thumb: escape when showing code or user text, sanitize when you must actually insert markup.

Where It Fits

Technical writers use it to show HTML, XML, and SVG samples inside blog posts and documentation. Developers escaping user-submitted text before rendering it. Template authors protecting dynamic values inserted into HTML email. Anyone decoding garbled, entity-filled text copied from a legacy system or an over-eager CMS.

Frequently Asked Questions

What exactly does safe mode escape, and what does full mode add?

Safe mode replaces only five characters: ampersand, less-than, greater-than, double quote, and apostrophe. Full mode escapes those same five, then converts every remaining character below U+0020 or above U+007E into a decimal numeric reference, so the result is pure ASCII.

Why did my full-mode output turn into a string of &#NNN; codes?

That is expected. Full mode represents every non-ASCII character as its decimal Unicode code point, so an accented letter or a currency symbol becomes something like &#233;. This keeps the text readable on pages or systems that do not declare a UTF-8 charset.

Does decoding &nbsp; give me a non-breaking space?

No. This decoder maps &nbsp; to an ordinary space (U+0020), not a non-breaking space (U+00A0). Decoding and then re-encoding will not restore the original entity.

Why does encoding already-encoded text produce &amp;lt;?

The ampersand in &lt; is itself a character that safe mode escapes, so the input &lt; becomes &amp;lt;. That is double encoding: the browser displays the literal text &lt; instead of the < character.

Can full mode handle emoji and accented letters?

Yes. Full mode walks the string by Unicode code point, so an emoji is emitted as a single numeric reference such as &#128512; rather than being split into surrogate halves.

Is HTML encoding enough to sanitize untrusted HTML?

No. Encoding the five dangerous characters stops text from being interpreted as markup, but it does not validate input, strip tags, or neutralize dangerous URLs such as javascript:. For rendering untrusted markup, use a purpose-built sanitizer.

Reviewed by the HandyTools Hub team · Last updated