Tools
HTML Encoder and Decoder
Encode text to HTML entities or decode entities back to readable text. Essential for displaying code as text on web pages and for preventing XSS vulnerabilities.
HTML entities: the bridge between code and visible text
HTML reserves a few characters for its own syntax: the less-than and greater-than signs (< and >) delimit tags, the ampersand (&) starts entities, and quotes delimit attributes. When you need to show these characters as text on the page, you cannot use them directly, because the browser would read them as markup. The solution is HTML entities, which represent these symbols in a way the parser treats as content rather than structure.
This tool converts in both directions: it encodes plain text into HTML entities (useful for including sample code in articles and documentation), or decodes entities back to the original readable text (useful for cleaning up double-encoded content or viewing the original text of an HTML fragment copied from another source).
Why HTML entities exist and which ones matter most
The five most critical entities are: < for <, > for >, & for &, " for " and ' for '. These are the only characters that must be encoded in HTML for the document to be valid. There are hundreds of additional named entities for math symbols, currencies, accented letters and typographic characters such as the em dash (—), the ellipsis (…) and the non-breaking space ( ).
With UTF-8 now the default encoding on the web, the need for entities for accented characters (such as é for é or ñ for ñ) has faded: it is simpler and more readable to include the character itself in the HTML when the file is saved as UTF-8. The exception is the five reserved characters above, which always need encoding regardless of the document's encoding.
XSS: when missing encoding becomes a security vulnerability
Cross-Site Scripting (XSS) has consistently been one of the most prevalent web vulnerabilities, appearing in the OWASP Top 10 for over a decade. The attack exploits missing output encoding: if a comment field accepts free text and that text is displayed in HTML without being encoded, an attacker can insert a <script> tag that runs malicious code in other users' browsers.
The consequences range from stealing session cookies (enabling account hijacking) to phishing (redirecting to fake pages), keylogging (capturing what users type into forms) and cryptocurrency mining in the victim's browser. The most effective defense is simple: never insert user content into HTML without encoding it first. Modern frameworks do this automatically, but legacy code or careless use of DOM APIs is still a frequent source of XSS vulnerabilities.
Encoding in different contexts: HTML, attributes, JavaScript and URLs
The context where a value is inserted determines which kind of encoding is needed. In the HTML body (between tags), entity encoding of the five reserved characters is enough. In HTML attributes, quotes must be encoded too ("). In inline JavaScript strings, the encoding is different: you use JavaScript escapes (\', \", \n). In URLs, you use percent-encoding (%20 for a space, %26 for &).
Mixing contexts is a common source of bugs and vulnerabilities. Putting HTML-encoded text into a JavaScript string produces unexpected content; putting unencoded text into an href attribute can allow javascript: URL injection. Security analysis tools such as Snyk, SonarQube and Burp Suite catch these context errors automatically during code reviews.
Double encoding: when entities get encoded more than once
A common problem in systems that process HTML in several steps is double encoding: &lt; instead of <. It happens when a system encodes data that is already encoded, producing text that literally shows "<" on the page instead of "<". The problem is especially visible in WYSIWYG editors, comment systems and platforms that run content through a pipeline of several transformations.
The fix is to make sure encoding happens exactly once, at the moment raw data is inserted into an HTML context. Data that is already HTML (such as CMS content) should not be encoded again. This tool can help diagnose double encoding: if the decoded result still contains HTML entities, the original content was encoded more than once.
Frequently asked questions
What are HTML entities and why do they exist?
HTML entities are character sequences that represent reserved or special symbols in HTML. HTML uses '<' and '>' to delimit tags; if you want to display those characters as text, you need '<' and '>'. The '&' starts entities, so it must itself be written as '&'. Other characters such as quotes ('"'), the apostrophe (''') and special symbols (©, ®, €) also have entity representations.
Why use & instead of a bare & in HTML?
The '&' character starts an HTML entity. If you write '©' in HTML, the browser displays '©'. But if you want to display '©' literally as text, you need to write '&copy;'. Using a bare '&' in HTML, especially in URLs inside href attributes, can cause unexpected behavior in validators and some browsers. Best practice is to always encode '&' as '&' in HTML attributes.
How does HTML encoding prevent XSS attacks?
XSS (Cross-Site Scripting) happens when an attacker injects malicious JavaScript into a web page through user input fields. If a comment such as '<script>document.cookie</script>' is submitted in a form and displayed without encoding, the script runs in the victims' browsers. By encoding the output, turning '<' into '<' and '>' into '>', the text is displayed as literal characters instead of executable code. It is one of the most fundamental defenses in secure web development.
What is the difference between named and numeric HTML entities?
Named entities have a readable name: '©' (©), '€' (€), '<' (<). Numeric entities use the character's Unicode code point: '©' for © (decimal) or '©' (hexadecimal). Both produce the same result. Numeric entities have the advantage of working for any Unicode character, even those without a defined HTML name. For the basic reserved characters (<, >, &, ", '), always use named entities for readability.
What are CDATA sections and when should you use them as an alternative?
CDATA (Character Data) is a section in XML and XHTML where the content is treated as literal text, not markup. The syntax is: <![CDATA[ content with < > & unencoded ]]>. In strict XHTML, inline scripts and styles used CDATA to avoid conflicts with the XML parser. In plain HTML5, CDATA is not interpreted the same way, and entity encoding remains the most compatible and safest approach for displaying special characters in text content.
When is server-side encoding mandatory versus optional on the client?
Output encoding on the server is mandatory for any user-supplied data that is rendered as HTML: comments, names, addresses, search fields. Modern frameworks like React, Vue and Angular do this automatically when you use standard interpolation ({variable} or {{variable}}), but using innerHTML or dangerouslySetInnerHTML bypasses that protection. On the server, functions such as htmlspecialchars() in PHP, html.escape() in Python and HtmlEncoder.Default.Encode() in .NET are the right tools.

