Skip to content

HTML Encoder: Escape Code for Safe Display

Runs 100% in your browser — your text never leaves this page, and nothing is uploaded or stored.

This html encoder escapes the five markup characters — & < > and both quotes — into entities so code displays on a page instead of running. Use it to escape html characters online and convert special characters to html entities — ampersand, angle brackets and both quotes — so code displays on a page instead of running.

How to Use the HTML Encoder

  1. Paste your text into the box — or press Load sample to encode the example snippet with its quotes and comparisons.
  2. Choose the mode: Encode → entities to make text safe for a page, Decode entities → text to clean encoded copy.
  3. Read the converted text in the result box — it updates as you type or switch modes.
  4. Copy the result into your page, document or editor.

About this tool

Paste a code snippet into an HTML page without escaping it, and the browser will try to run it instead of show it — or worse, break your layout entirely. HTML encoding replaces the characters that have meaning in markup with entity references the browser displays literally. Encoding covers the five characters that matter: & becomes &amp;, < becomes &lt;, > becomes &gt;, double quotes become &quot; and single quotes become &#39;. The ampersand is handled first, so every & in your text — including one that happens to begin an existing entity — is escaped exactly once, in the only safe order. Decoding reaches much further than encoding needs to. Real-world text carries hundreds of entities — &copy;, &eacute;, &nbsp;, numeric forms like &#169; — and the decoder resolves all of them using your browser’s own HTML parser, the same authority that renders web pages. That makes it the right rescue tool for the entity-littered copy that CMS exports and page sources leave behind. Writers of tutorials and documentation use the encoder daily, and editors use the decoder to clean rescued copy. Both directions run entirely in your browser — the code you are escaping, tokens and all, never leaves your device. Encoding for transport rather than display? The base64 encode decode tool turns the same text into Base64 and back. MDN's glossary entry on character references explains the named and numeric forms this tool converts between. HTML encode: turn raw code into entities so it displays safely instead of running in the browser.

Worked example

Here is the sample snippet that comes with the tool, run through the default Encode mode: You paste
<p class="intro">Tom & Jerry said "5 > 3 & 2 < 4" — that’s math!</p>
You get
&lt;p class=&quot;intro&quot;&gt;Tom &amp; Jerry said &quot;5 &gt; 3 &amp; 2 &lt; 4&quot; — that&#39;s math!&lt;/p&gt;
Watch the order of events: the & in “Tom & Jerry” became &amp; — escaped once, not nested — and the angle brackets of the <p> tag are now &lt;p&gt;, so a browser would display this snippet as text instead of treating it as a paragraph. The apostrophe in “that’s” took the numeric form, &#39;.

Features

  • All five critical escapes: & < > and both quote styles, applied in the safe order, ampersand first.
  • A decoder with the browser’s full vocabulary — every named and numeric entity, not just the famous five.
  • Round-trip safe: encode here, decode here, and the text returns character for character.
  • Instant conversion as you type — snippets, whole pages of code, entity-littered exports.
  • The right tool for displaying code in tutorials, docs and comments without it executing.
  • Private by design: escaping happens in your browser; your code never leaves your device.

HTML Encoder FAQs

Which characters get encoded?The five that matter for safe HTML: & becomes &amp;, < becomes &lt;, > becomes &gt;, double quotes become &quot;, and single quotes become &#39;.
Why does decoding handle more than encoding produces?Real-world text contains hundreds of named entities (&copy;, &nbsp;, &eacute;…). The decoder resolves all of them using the browser’s own parser.
Is HTML encoding the same as URL encoding?No. HTML entities protect text inside web pages; percent-encoding protects text inside URLs. They solve different problems and are not interchangeable.
Is my code kept private?Yes, escaping happens entirely in your browser.
My text already contains &amp; — will encoding break it?No. Encoding escapes the & itself, producing &amp;amp;, which a browser displays as the literal text “&amp;” — correct when the original characters are what you want shown. If the text was meant to be decoded instead, use Decode mode.
Does it encode accented letters and emoji too?No — encode mode only touches the five markup characters. Accented letters and emoji are valid in modern UTF-8 pages and pass through unchanged.
What happens if I decode text that has no entities?It passes through unchanged — decoding plain text is a harmless no-op, so it is safe to run over mixed content where only some lines carry entities.
More text encoder decoder tools →