HTML Encoder / Decoder

Encode or decode HTML entities safely.

Enter HTML to convert

The Five Characters That Break HTML

HTML gives special meaning to a handful of characters, so putting them into a page as-is either breaks rendering or opens a security hole. Encoding replaces them with named entities the browser displays literally:

CharacterEntityRole in HTML
&&Starts every entity — must always be encoded first
<&lt;Opens a tag
>&gt;Closes a tag
"&quot;Delimits attribute values
'&#39;Delimits attribute values (single-quoted)

Example: <div class="hello">World & "Friends"</div> encodes to &lt;div class=&quot;hello&quot;&gt;World &amp; &quot;Friends&quot;&lt;/div&gt; — paste that into a page and the browser shows the markup as text instead of rendering a div.

Encode and Decode Modes

Switch modes with the toggle at the top; conversion happens live as you type. Encode replaces the five special characters above. Decode is more general: it resolves any entity the browser knows — named (&nbsp;, &copy;, &eacute;), decimal (&#233;), and hexadecimal (&#xE9;) — so it cleans up entity-littered text scraped from web pages or CMS exports in one pass.

Why This Matters: Displaying Code and Preventing XSS

  • Showing code on a page: to display an HTML snippet in a blog post or docs, it must be entity-encoded, otherwise the browser renders it instead of showing it.
  • XSS prevention: user input echoed into HTML without encoding lets an attacker inject <script> tags. Encoding on output turns the attack into harmless visible text. It's the single most important output-escaping rule in web development.
  • Fixing double-encoded text: if you see &amp;lt; in rendered output, the text was encoded twice. Run it through decode until it stabilizes.

HTML Encoding vs. URL Encoding

They solve different problems and aren't interchangeable: HTML entities make text safe inside markup; percent-encoding makes text safe inside URLs. A value that goes into a link's href query string needs the URL encoder; the visible link text needs this tool. Everything here runs entirely in your browser — nothing you paste is sent to a server. Also useful alongside: the Markdown to HTML converter for generating markup and the Base64 tool for data URIs.

Frequently Asked Questions

Why do I need to encode HTML?
Characters like <, > and & have structural meaning in HTML. Encoding them as entities (&lt;, &gt;, &amp;) makes the browser display them as text instead of interpreting them — essential for showing code and for preventing XSS attacks.
What characters are encoded?
The five HTML-critical characters: & → &amp;amp;, < → &amp;lt;, > → &amp;gt;, " → &amp;quot;, and ' → &amp;#39;. That set is exactly what safe output-escaping requires.
Can it decode entities like &nbsp; and &#233;?
Yes. Decode mode resolves all entities the browser understands — named, decimal, and hexadecimal — not just the five that encode mode produces.
Is this the same as URL encoding?
No. HTML encoding makes text safe inside markup; URL (percent) encoding makes text safe inside URLs. A query-string value needs %-encoding, visible page text needs entities — use each in its own context.
Does encoding prevent all XSS?
It covers the most common case: user text echoed into HTML body or quoted attributes. Other contexts (JavaScript strings, CSS, URLs) need their own escaping rules — encoding is necessary but context-specific.