HTML Decode API: The Complete Guide

Need to decode HTML entities back to characters? This guide covers everything you need to know about HTML decoding via API, including handling named and numeric entities.

What is HTML Decoding?

HTML decoding converts HTML entities back to their original characters. This is the reverse of HTML encoding and is necessary when processing HTML content that needs to be displayed as plain text or used in non-HTML contexts.

Example: "&lt;" becomes "<" and "&amp;" becomes "&"

Types of HTML Entities

HTML entities come in different formats:

  • Named entities: &lt; &gt; &amp; &nbsp;
  • Decimal numeric: &#60; &#62; &#38;
  • Hexadecimal numeric: &#x3C; &#x3E; &#x26;
Note: A robust decoder handles all entity formats - named, decimal, and hexadecimal - as they all represent valid HTML.

Using the HTML Decode API

TinyFn provides a simple endpoint to decode HTML:

API Request
POST https://api.tinyfn.io/v1/text/html-decode
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "&lt;p&gt;Hello &amp; welcome!&lt;/p&gt;"
}
Response
{
  "decoded": "<p>Hello & welcome!</p>",
  "original_length": 44,
  "decoded_length": 25
}

Parameters

Parameter Type Description
text string The HTML-encoded text to decode (required)
decode_numeric boolean Decode numeric entities (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/text/html-decode',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: '&lt;p&gt;Hello World&lt;/p&gt;'
    })
  }
);
const result = await response.json();
console.log(result.decoded); // "<p>Hello World</p>"

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/text/html-decode',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': '&lt;p&gt;Hello World&lt;/p&gt;'}
)
result = response.json()
print(result['decoded'])  # "<p>Hello World</p>"

cURL

curl -X POST "https://api.tinyfn.io/v1/text/html-decode" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "&lt;p&gt;Hello World&lt;/p&gt;"}'

Common Use Cases

  • Data Processing: Decode HTML from APIs or databases
  • Web Scraping: Clean extracted HTML content
  • Content Migration: Prepare content for new systems
  • Text Analysis: Get raw text from HTML-encoded content
  • RSS/Feed Processing: Decode feed content for display

Best Practices

  1. Handle all formats: Support named, decimal, and hex entities
  2. Preserve unknown entities: Don't corrupt unrecognized sequences
  3. Be careful with security: Decoded content may need re-encoding for display
  4. Test edge cases: Handle malformed entities gracefully

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-text": {
      "url": "https://api.tinyfn.io/mcp/text/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.

Try the HTML Decode API

Get your free API key and start decoding HTML in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key