Utility Coder
Back to Blog
encoding

HTML Decode

Andy Pham
html decode, html decode, html decode online

Ready to try HTML Decode?

Access the free online tool now - no registration required

Open Tool

HTML Decode - Complete Guide

HTML decoding converts HTML entities back to their original characters. This is needed when processing HTML content that contains encoded entities, extracting plain text from HTML, or working with data that was HTML-encoded for safe storage.

How It Works

The decoder identifies entity patterns (&name; or &#number; or &#xhex;) and replaces them with corresponding characters. Named entities use a lookup table, numeric entities convert the number to its Unicode character.

Technical Details

Entity types: named (& → &), decimal (& → &), hexadecimal (& → &). There are 252 named entities in HTML5. Numeric entities support any Unicode code point. Invalid entities may be passed through unchanged or trigger errors.

Common Use Cases

  1. Extract Plain Text: Convert HTML content to plain text for processing.
    • Example: &amp; and &lt;br&gt; → & and <br>
  2. API Data Processing: Decode HTML-encoded data received from APIs.
  3. Search Indexing: Convert HTML content to searchable plain text.
  4. Data Migration: Decode legacy data that was stored HTML-encoded.

Code Examples

JavaScript HTML Decoding

// Using DOM (browser)
function htmlDecode(str) {
  const doc = new DOMParser().parseFromString(str, 'text/html');
  return doc.documentElement.textContent;
}

// Using textarea (browser, simpler)
function htmlDecode(str) {
  const textarea = document.createElement('textarea');
  textarea.innerHTML = str;
  return textarea.value;
}

// Node.js (he library)
import he from 'he';
he.decode('&lt;div&gt;');  // '<div>'

Browser DOM decodes automatically. For Node.js, use the he library for comprehensive entity support.

Python HTML Decoding

import html

# Decode entities
text = html.unescape('&lt;script&gt;')
# '<script>'

# Handles numeric entities too
text = html.unescape('&#60;&#x3E;')
# '<>'

# BeautifulSoup for HTML content
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
plain_text = soup.get_text()

html.unescape decodes all HTML entities. BeautifulSoup extracts plain text from HTML documents.

Tips & Best Practices

  • Use DOM-based decoding in browsers for safety
  • Be careful decoding content that will go back into HTML
  • Test with various entity types (named, decimal, hex)
  • Consider using libraries for comprehensive entity support
  • Decode only when moving to non-HTML context

Common Mistakes to Avoid

  • Decoding then re-encoding (wastes processing)
  • Decoding user input that will be displayed in HTML (XSS risk)
  • Not handling numeric entities (' vs ')
  • Assuming all entities are valid

When to Use This Tool

Use HTML decoding when extracting text from HTML, processing HTML-encoded API responses, or converting data for non-HTML display. Always consider security when decoded content will be displayed.

Frequently Asked Questions

When should I decode HTML entities?

Decode when: extracting plain text from HTML, processing API data that's HTML-encoded, migrating data between systems, or displaying in non-HTML contexts. Don't decode if you're going to display in HTML again.

What about invalid entities?

Invalid named entities (&invalid;) are typically passed through unchanged. Numeric entities outside valid Unicode range may throw errors or produce replacement characters. Handle edge cases based on your data source.

How do I decode just some entities?

Full decoding converts all entities. To decode selectively (just & but not <), use targeted replacement rather than full decoding.

Get Started

Ready to try HTML Decode? Use the tool now - it's free, fast, and works right in your browser.


Last updated: June 27, 2026

Start using HTML Decode

Free, fast, and privacy-focused - try it now

Launch Tool