Skip to content
Converter Tools

HTML Encoder

Convert special characters into safe HTML entities instantly — escape <, >, &, quotes and non-ASCII text for safe display in any web page.

  • Free forever
  • No signup
  • Runs 100% in your browser
Use the HTML Encoder
Need the reverse? HTML Decoder
Encoded output (displayed as source — never executed)

Escaped entities appear here as you type

Input0 chars
Output0 chars
Entities0

What is an HTML encoder?

HTML encoding (escaping) converts characters that have special meaning in HTML — like <, >, & and quotes — into character entities such as &lt; and &amp;. Encoded text renders as literal characters in the browser instead of being interpreted as markup, which is essential for displaying code examples and preventing XSS injection.

Why raw text breaks web pages

HTML is a markup language, which means certain characters are instructions, not content. A < tells the browser "a tag starts here"; an & says "an entity starts here". When text that was never meant to be markup contains those characters — a blog comment reading "I love <div> elements", a forum post comparing a > b — the browser obediently parses them as structure. The comment vanishes into a phantom element, the rest of the page nests inside it, and the layout collapses in ways that are miserable to debug.

Escaping converts those instruction characters into inert display characters. The text <div> becomes &lt;div&gt;, which the browser renders as the literal four characters "<div>" on screen. Your content says exactly what you typed, and the page structure stays untouched.

Attribute values deserve special mention because they are the easiest place to get bitten. A quote inside an attribute — title="He said "hello"" — terminates the attribute early, and whatever follows can become a new, attacker-controlled attribute. Encoding " as &quot; and ' as &#39; closes that hole, which is why this tool's Basic mode always escapes all five core characters rather than the minimal three some tutorials suggest.

How encoding neutralizes XSS attacks

Cross-site scripting happens when attacker-supplied text reaches a page as executable markup: a comment containing <script>stealCookies()</script> that the site renders raw. If every dynamic value is escaped at output time, that input becomes &lt;script&gt; — visible, harmless text. The payload never executes because the browser never sees a real tag.

One honest caveat: encoding is one layer, not a security strategy by itself. Different contexts (HTML body, attributes, JavaScript strings, URLs) need different escaping rules, and mature apps pair output encoding with input validation, Content Security Policy headers and sanitization libraries. But correct escaping is always the foundation — and testing what your escaped output actually looks like is exactly what this tool is for.

Encoding for display vs sanitizing for security

These two operations are constantly confused, and the difference matters. Encoding for display is what this tool does: transform text so the browser shows it literally. It is deterministic, reversible and context-specific — you encode because you want the characters visible on the page, whether you are publishing a code tutorial, documenting an API payload or quoting HTML in an email.

Sanitizing for security is a different discipline: parsing untrusted HTML and removing anything dangerous — scripts, event handlers, rogue iframes — while keeping safe formatting intact. Sanitization requires a real parser and an allowlist, which is why libraries like DOMPurify exist. Encoding untrusted input at output time is your baseline defense, but if you intentionally accept HTML from users, you need a sanitizer too.

The practical workflow: store content raw in your database, escape it every time you render it into a page, and encode by hand with a tool like this one whenever you are preparing examples, templates or documentation. Encoding should happen at the last possible moment — at output — because double-encoding stored content is how you end up with &amp;lt; showing on the page.

Named vs numeric entities, and when extended mode helps

Named entities like &amp; and &copy; are self-documenting — anyone reading your source knows what character was intended. Numeric entities (&#38; decimal, &#x26; hexadecimal) work for every Unicode code point, including the thousands of characters that have no named form. All three styles are equally valid HTML; pick named for readability, numeric for completeness, hex to match byte-oriented documentation.

Extended mode converts every non-ASCII character — é, ©, €, emoji — into entities. That is invaluable when content must survive legacy systems: databases stuck in Latin-1, email templates that mangle UTF-8, or build pipelines that strip high bytes. café becomes caf&eacute; (or caf&#233;), which renders identically in any encoding. Modern UTF-8 pages rarely need it, but when you need it, nothing else will do.

Converter Tools

Why use our html encoder?

XSS-safe output

Escaped code displays as inert text and can never execute — verify your escaping before it ships.

Three entity styles

Named (&amp;), decimal (&#38;) or hexadecimal (&#x26;) output to match your codebase conventions.

Extended mode

Converts accented letters, symbols and any non-ASCII character to entities for legacy encodings.

Completely private

Paste user content, templates or unreleased copy — encoding runs entirely in your browser.

HTML Encoder examples

Escaping results for the three entity styles and both scopes.
InputOptionsEncoded output
<div class="a">Basic · Named&lt;div class=&quot;a&quot;&gt;
Tom & JerryBasic · NamedTom &amp; Jerry
© 2024Extended · Named&copy; 2024
caféExtended · Named / Decimalcaf&eacute; / caf&#233;
a > b & 'quotes'Basic · Hexa &gt; b &amp; &#x27;quotes&#x27;

How to use this html encoder

  1. Paste the text or code you want to escape into the input.

  2. Choose Basic (the 5 core characters) or Extended (all non-ASCII) scope.

  3. Pick an entity style: named, decimal or hexadecimal.

  4. Copy the encoded output into your HTML, template or CMS.

Common mistakes to avoid

  • Forgetting to escape & first.Ampersands must be encoded before anything else, or &lt; degrades into a broken "&amp;lt;" mess. This tool escapes character-by-character, so ordering is always correct.

  • Double-encoding CMS content.If output contains &amp;lt;, the input was already encoded. Decode it first with our HTML Decoder, then re-encode once.

  • Relying on encoding alone for security pipelines.Escape at output time AND validate at input time. Encoding is one layer; add CSP headers and sanitization for real defense.

  • Encoding entire documents.Only encode text content and attribute values — never your actual HTML structure, or the page renders as source code.

Frequently asked questions

Explore more Converter Tools

Encode, decode and convert between formats developers use daily. Every tool is free, instant and private.

View Converter Tools