HTML Encode & Decode - Escape HTML Entities Online (Free)

Instantly html encode decode text and HTML entities in your browser. Free, private, no sign-up. Paste your text and get safe encoded or decoded output in

Tool options

Mode

Input
70 chars · 1 lines · 72 bytes
Output

Paste your text, get safe HTML – or turn encoded text back to readable

This tool converts raw text into HTML-encoded form (so special characters can't break your markup) and decodes encoded strings back into plain, readable text. Paste your input above, choose Encode or Decode, and the result appears immediately.

Everything runs in your browser. Your text is never uploaded to any server, so passwords, private content, and API snippets stay completely private.

How to html encode decode in three steps

  1. Paste your text (or HTML) into the input box above.
  2. Choose Encode to escape special characters, or Decode to restore them.
  3. Copy the output with one click and use it wherever you need it.

Worked example

Encoding (plain text → safe HTML)

Say you want to display a code snippet inside a web page without the browser interpreting it as markup. Your raw input:

<script>alert("Hello & welcome!")</script>

After encoding, every special character is replaced with an HTML entity – a short code the browser renders as a visible character instead of acting on it:

&lt;script&gt;alert(&quot;Hello &amp; welcome!&quot;)&lt;/script&gt;

Paste that encoded output into your HTML and the browser shows the original angle brackets and quotes as text – not as an executable script tag.

Decoding (HTML entities → plain text)

Paste &copy; 2024 &lt;YourBrand&gt; and click Decode. You get:

© 2024 <YourBrand>

The five predefined HTML escape characters

HTML has five characters that must be escaped when they appear in content. Using their entity equivalents prevents the browser from treating your text as markup and is the first line of defence against XSS (cross-site scripting) – a common web security attack where malicious code is injected into a page through unescaped input.

Character Entity name Numeric entity Why escape it?
<&lt;&#60;Opens a tag – unescaped, the browser reads it as markup
>&gt;&#62;Closes a tag – same risk
&&amp;&#38;Starts any entity – must be escaped to appear literally
"&quot;&#34;Breaks out of a quoted HTML attribute value
'&#39; / &apos;&#39;Breaks out of a single-quoted attribute value

The HTML specification is maintained by WHATWG. The full list of named character references is documented at html.spec.whatwg.org – Named character references.

How to do this in code

If you need to encode or decode HTML entities inside your own project, here are the idiomatic one-liners.

JavaScript (browser)

// Encode
function encodeHTML(str) {
  const el = document.createElement('div');
  el.appendChild(document.createTextNode(str));
  return el.innerHTML;
}

// Decode
function decodeHTML(str) {
  const el = document.createElement('div');
  el.innerHTML = str;
  return el.textContent;
}

Python 3

import html

# Encode (escape)
html.escape('<script>alert("xss")</script>')
# Returns: '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;'

# Decode (unescape)
html.unescape('&lt;b&gt;Hello&lt;/b&gt;')
# Returns: '<b>Hello</b>'

PHP

<?php
// Encode
$safe = htmlspecialchars($input, ENT_QUOTES | ENT_HTML5, 'UTF-8');

// Decode
$original = htmlspecialchars_decode($safe, ENT_QUOTES | ENT_HTML5);
?>

How it works under the hood

The encoder scans every character in your input. When it finds one of the five reserved characters (< > & " '), it replaces it with the matching named or numeric HTML entity. All other characters pass through unchanged.

The decoder does the reverse: it finds entity patterns like &amp; or &#60; and replaces them with the real character. The underlying approach follows the MDN definition of HTML entities.

When to encode, when to decode – and when neither applies

Encode when you need to

  • Display user-submitted content or code snippets safely inside a web page
  • Store HTML-safe strings in a database or JSON field
  • Write content inside an HTML attribute (title, alt text, data attributes)
  • Send HTML over XML-based APIs or RSS feeds

Decode when you need to

  • Read encoded content scraped or copied from a webpage's HTML source
  • Process email bodies or RSS feed text that arrived with entities intact
  • Debug a string that looks like &amp;copy; instead of ©

When this tool is NOT the right fit

  • URL encoding – if you need %20 instead of a space, use a URL encoder, not an HTML entity tool.
  • Base64 – for encoding binary data or images. Different algorithm entirely.
  • Full HTML rendering – if you want to preview Markdown turned into HTML, try the Markdown Preview – See Your Markdown as HTML Instantly.

Bottom line: if a special character is causing broken layouts, mystery symbols, or security warnings in your HTML, paste it here and fix it in seconds.

Frequently asked questions

Is my text uploaded anywhere when I use this tool?+
No. The entire encode/decode process runs in your browser using JavaScript. Nothing you type or paste is ever sent to a server, logged, or stored. You can use it safely with sensitive content.
What is the difference between HTML encoding and URL encoding?+
HTML encoding replaces characters like < and & with HTML entities (e.g. &lt;) so they display correctly in a web page. URL encoding replaces characters with percent-codes (e.g. %20 for a space) so they travel safely in a URL. They solve different problems and are not interchangeable.
What is the difference between HTML encoding and escaping?+
'HTML encoding' and 'HTML escaping' mean the same thing in everyday use – both describe replacing reserved characters with HTML entities. Some tools also call this 'HTML sanitising', though technically sanitising can involve removing tags entirely, not just escaping them.
How do I HTML encode a string in Python?+
Use the built-in html module: html.escape(your_string). To decode, call html.unescape(your_string). Both are available in Python 3.2+ and need no extra libraries.
How do I HTML encode in JavaScript without a library?+
Create a temporary div element, set its textContent to your string, and read its innerHTML. That gives you the encoded version. To decode, set innerHTML and read textContent. The worked example on this page shows the full two-function snippet.
Does this tool handle all HTML entities, or just the five basic ones?+
It encodes the five characters that are strictly required for safe HTML output (<, >, &, ", '). Encoding every possible Unicode character as a named entity is rarely necessary in modern UTF-8 pages – but if you need a specific named entity like &copy; or &eacute;, just type the entity directly into your HTML.
Is this tool free? Do I need to sign up?+
Completely free, no account required. Open the page, paste your text, and copy the result. There are no usage limits.
Why does my decoded text still show &amp; instead of &?+
This usually means the text was double-encoded – encoded twice. Run it through the decoder a second time. Each pass removes one layer of entity escaping.