Skip to main content

HTML Encoder & Decoder

Encode HTML into safe entities and decode HTML entities back into readable text instantly in your browser. Includes live preview rendering.

Input HTML
Output Result

Live Visual Preview

Renders decoded HTML
Ready
Chars: 0 Entities: 0

Advertisement

HTML Character Encoding, Entity Decoding, and Safe Markup Display

Paste a snippet like <button class="save">Save & Continue</button> straight into an HTML document or email template, and the browser won't print those characters on screen. It immediately enters tag parsing mode, creates a clickable button, and drops your literal angle brackets. That same parser behavior runs in reverse when data goes through two escaping passes without anyone noticing, turning a simple label into Tom &amp; Jerry or raw entity noise on a live page.

HTML encoding solves this boundary problem by swapping reserved syntax characters for character references that the parser displays as plain text rather than structure. Decoding does the inverse, turning stored named or numeric entities back into ordinary symbols so you can inspect legacy payloads, clean up scraped feeds, or read escaped markup inside an HTML template. Everything in this tool runs directly inside your browser tab without uploading snippets to a server.

The Five Syntax Characters That Trigger the HTML Parser

Under the HTML specification, five ASCII characters carry structural meaning in element content or attribute values. When you click Encode HTML in this tool, it targets those exact five characters in a fixed sequence:

Character Encoded Output Numeric Equivalent Why It Matters in Parsing
& &amp; &#38; / &#x26; Opens every character reference; must always be escaped first
< &lt; &#60; / &#x3C; Switches the HTML tokenizer from text data into tag opening state
> &gt; &#62; / &#x3E; Closes tags and comment boundaries like -->
" &quot; &#34; / &#x22; Terminates double quoted HTML attribute strings
' &#39; &#39; / &#x27; Terminates single quoted HTML attribute strings

Notice two deliberate implementation details here. First, & is replaced before <, >, ", or '. If a script replaced < with &lt; first and ran the ampersand pass afterward, that freshly inserted & would be escaped a second time into &amp;lt;. Second, apostrophes become numeric &#39; rather than &apos;. XML and HTML5 support &apos;, but HTML4 and older email clients did not recognize that name and printed it verbatim. Numeric &#39; renders cleanly across every parser still in use.

Encoding Scope Versus Full Entity Decoding

Encoding and decoding are intentionally asymmetric in this workspace. When you run Encode HTML, only those five reserved ASCII symbols are transformed. Letters with accents, currency marks like €, mathematical symbols, and emoji stay intact as UTF-8 characters. On any modern page declaring <meta charset="UTF-8">, leaving normal Unicode characters untouched keeps your HTML readable and compact instead of bloating every paragraph with numeric entity codes.

Clicking Decode HTML works across the entire HTML5 entity catalog. Internally, the tool assigns your text to the innerHTML property of a detached <textarea> element and reads back its value. Because browsers treat <textarea> as raw character data, the browser's native HTML parser resolves named entities (&copy;, &nbsp;, &reg;), decimal codes (&#169;), and hexadecimal codes (&#xA9;) accurately without instantiating DOM nodes or executing inline scripts.

Where Escaping Protects You and Where It Fails

HTML encoding is the right defense for text nodes and quoted attributes, yet context rules everything on the web. Applying only HTML entity escaping in the wrong slot creates subtle bugs or security gaps:

  • Element text content: Inside tags like <p>, <td>, or <code>, escaping < and & keeps user strings from injecting tags or fake markup.
  • Quoted attribute values: Inside title="..." or value='...', escaping quotes stops an attacker from closing the attribute early and appending an event handler such as onmouseover.
  • Unquoted attributes: Writing data-label=USER_INPUT without outer quotes breaks even after encoding all five characters, because spaces, tabs, and backticks still end the attribute value. Always wrap attributes in quotes.
  • URL attributes like href and src: Browsers decode HTML entities inside attributes before handing the resulting string to the URL parser. A link written as href="javascript&#58;alert(1)" contains zero raw angle brackets or quotes, yet still runs JavaScript unless you validate the scheme (https:, http:, or relative paths).
  • Inside <script> or <style> blocks: HTML parsers do not decode character references inside raw text script elements. Putting &quot; inside inline JavaScript literally places those six characters into your code, breaking syntax or failing to stop string breakouts. Use JSON serialization or JavaScript escaping there instead.

Catching Double Encoding and Using Live Preview Safely

Double encoding happens when server middleware escapes a string before saving it to a database, and a front end template escapes it a second time on render. Visitors end up seeing literal &quot;Hello&quot; in headings or product titles. You can diagnose that bug here in seconds: paste the messy string, click Decode HTML, and watch the Entities counter above the editor. If the decoded output still shows entities like &lt; or &amp;, the source string was encoded multiple times. Click Swap to move the decoded output back into the input box and decode one layer further until clean text appears.

Beneath the dual editors sits a Live Preview frame designed for quick layout inspection. In Encode mode, the preview renders your original input markup so you can confirm what your snippet looks like as actual HTML alongside the escaped code you plan to publish in documentation. In Decode mode, the preview renders the newly decoded HTML instead. For safety when checking untrusted snippets, the preview loads inside an iframe configured with an isolated opaque origin and script execution disabled, so HTML layout and CSS render while embedded scripts stay inert.

Advertisement

Named, Decimal, and Hexadecimal Entity Formats

Every character reference resolves to the same Unicode code point regardless of notation. Teams write &copy; for readability in hand authored templates, while automated serializers often emit decimal &#169; or hexadecimal &#xA9; because any Unicode code point can be converted algorithmically without shipping a lookup dictionary of two thousand entity names.

One practical exception is XML and RSS feeds. Standard XML defines only five named entities: &amp;, &lt;, &gt;, &quot;, and &apos;. Using HTML named entities such as &nbsp; or &copy; inside a strict XML feed triggers a parser error unless they are converted to numeric references like &#160; or &#169;, or decoded directly into UTF-8 characters. When migrating HTML snippets into XML sitemaps or feeds, decoding the HTML entities first gives you clean characters that validate cleanly.

Quick Workflow Tips Inside This Editor

Keep Auto-Update enabled when cleaning short tags or debugging escaped JSON strings so each keystroke refreshes the output and Live Preview immediately. If you work with large HTML documents, check the Chars and Entities readouts in the toolbar to verify how many references remain before copying or downloading a .html file. Notice also that if you need reserved URL characters percent encoded (like turning spaces into %20 for query strings), use the URL Encoder & Decoder rather than HTML entities, since browsers treat URL percent encoding and HTML entity escaping as separate layers.