XhCode Online Converter Tools
50%

HTML Decoder


Enter the text to be HTML-decoded

Size : 0 , 0 Characters

The Decoded HTML:

Size : 0 , 0 Characters
HTML Decode

HTML Decoding is the process of converting HTML-encoded entities back into their corresponding characters. This is the reverse process of HTML encoding, where special characters in HTML (like <, >, &, " etc.) are represented by their respective HTML entities (e.g., &lt;, &gt;, &amp;, &quot;) for safe display in a browser. HTML decoding restores these entities back to the original characters.

Why HTML Decoding is Needed:
When you receive HTML-encoded content (e.g., from an API, database, or user input), you may need to decode the HTML entities back into the characters to display them as they were originally intended.

For example:

&lt; becomes <
&gt; becomes >
&amp; becomes &
&quot; becomes "
Example of HTML Decoding:
HTML Encoded String:

php-template

Hello &lt;b&gt;world&lt;/b&gt; &amp; &quot;everyone&quot;
After HTML Decoding:

bash

Hello <b>world</b> & "everyone"
How HTML Decoding Works:
Identify HTML Entities: Look for sequences that begin with & and end with ;, such as &lt;, &gt;, &amp;, and so on.
Convert HTML Entities Back to Characters: Replace the HTML entities with their corresponding characters.
HTML Decoding in Different Programming Languages:
JavaScript:
In JavaScript, you can decode HTML entities using the browser's DOM API by using an element's innerHTML property:

javascript

function htmlDecode(str) {
var element = document.createElement('div');
element.innerHTML = str;
return element.textContent || element.innerText;
}

let decoded = htmlDecode('Hello &lt;b&gt;world&lt;/b&gt; &amp; &quot;everyone&quot;');
console.log(decoded); // Outputs: Hello <b>world</b> & "everyone"
Python:
In Python, you can use the html module to decode HTML entities:

python

import html

encoded_text = 'Hello &lt;b&gt;world&lt;/b&gt; &amp; &quot;everyone&quot;'
decoded_text = html.unescape(encoded_text)
print(decoded_text) # Outputs: Hello <b>world</b> & "everyone"
PHP:
In PHP, you can use the htmlspecialchars_decode() function to decode HTML entities:

php

$encoded_text = 'Hello &lt;b&gt;world&lt;/b&gt; &amp; &quot;everyone&quot;';
$decoded_text = htmlspecialchars_decode($encoded_text);
echo $decoded_text; // Outputs: Hello <b>world</b> & "everyone"
When to Use HTML Decoding:
Displaying HTML Content: When you retrieve HTML-encoded content (such as from a database or an API), decoding it ensures that the original characters are shown as intended.
Processing User Input: If you are receiving HTML-encoded data (e.g., in form submissions or query parameters), decoding ensures you can work with the raw characters for further processing or display.
Example Use Case:
If you have an encoded HTML string from a form submission:

php-template

Hello &lt;b&gt;world&lt;/b&gt; &amp; &quot;everyone&quot;
After decoding, the output would be:

bash

Hello <b>world</b> & "everyone"
This makes it ready for rendering on a web page as the raw HTML or plain text.