Developer Tools

HTML Entity Encoder / Decoder

This free HTML Entity Encoder turns the five characters that break markup (&, <, >, double quotes and apostrophes) into &amp;, &lt;, &gt;, &quot; and &#39; (optionally every non-ASCII character too, as named, decimal or hex entities), and decodes any named, decimal or hex entity back into plain text. Both directions run entirely in your browser, so nothing you paste is uploaded.

Runs in your browser. Your files and text never leave your device - nothing is uploaded.

Encode and Decode HTML Entities Online

The Tools Kit’s free HTML Entity Encoder escapes the characters that break markup, turning &, <, >, double quotes and apostrophes into &amp;, &lt;, &gt;, &quot; and &#39;. It also works as an HTML entity decoder: paste encoded text and it converts every named, decimal or hex entity back into readable characters.

Use it when you need to show a code sample on a web page, escape HTML special characters before dropping text into a template, or unescape a string full of &amp; and &quot; codes. Both directions run in your browser, so nothing you paste is uploaded.

How to Use the HTML Entity Encoder

  1. 1

    Paste your text or HTML on the left

    Type or paste the plain text, code sample or HTML snippet you want to escape into the Plain Text / HTML box. It starts with a short sample you can replace.

  2. 2

    Choose the format and click Encode

    Pick named, decimal or hex entities, and whether to encode only the five reserved characters (&, <, >, " and ') or every non-ASCII character too. Press Encode and the result appears in the Encoded Entities box on the right.

  3. 3

    Or decode entities back to text

    Paste entity-encoded text into the right box and press Decode. Every named, decimal and hex entity is converted back to its character, and the result replaces the contents of the left box.

  4. 4

    Copy the encoded output

    Click Copy Encoded to put the contents of the right box on your clipboard, ready to paste into a template, CMS field, blog post or config file.

Both boxes are editable, and conversion only happens when you click a button, so you can tweak either side before converting. There is no sign-up and no limit on use.

Which Characters Need Escaping in HTML?

Only a handful of characters have special meaning to an HTML parser. The angle brackets open and close tags, the ampersand starts an entity, and the two quote marks end attribute values. These are the five characters the encoder always converts:

CharacterEncoded asNumeric formWhy it matters
&&amp;&#38;Starts every entity, so a literal ampersand must be escaped
<&lt;&#60;Opens a tag; unescaped it can turn text into markup
>&gt;&#62;Closes a tag; escaped for symmetry and safety
"&quot;&#34;Ends a double-quoted attribute value
'&#39; (this tool)&#39;Ends a single-quoted attribute value

By default everything else, including accented letters, currency symbols and emoji, passes through unchanged. On a page served as UTF-8 those characters display correctly without entities, so leaving them alone keeps the output readable. If the text is going somewhere that is not UTF-8, such as an old template or an ASCII-only system, choose “Those plus every non-ASCII character” and pick named, decimal or hex references. Strictly, > and the quote marks are only dangerous in certain places, but escaping all five everywhere is the simple, safe rule.

Worked Example: Escaping an HTML Snippet

The tool loads with this sample in the left box:

<div class="greeting">Hi & welcome!</div>

Clicking Encode produces:

&lt;div class=&quot;greeting&quot;&gt;Hi &amp; welcome!&lt;/div&gt;

Paste that second line into a page and visitors see the original tag as text instead of an invisible div. Paste it back into the right box and click Decode, and you get the original snippet again. The encoder replaces all five characters in a single pass, so an ampersand it has just written is never escaped a second time within the same run.

If you are publishing a longer code sample, tidy it with the code beautifier first and then encode it, so the indentation survives inside your <pre> block. Writing in Markdown instead? The Markdown to HTML converter escapes ampersands and angle brackets in your source as part of the conversion.

HTML Encoding vs URL Encoding and Other Escapes

Each place text can go has its own escaping rules. HTML entities protect text inside page content and quoted attributes. A value that goes into a link or query string needs percent encoding instead, which the URL encoder handles, turning a space into %20 and an ampersand into %26. Binary data or text that must survive any transport unchanged is usually wrapped with the Base64 encoder.

XML uses the same five escapes as HTML, so this encoder works for XML text values too. After escaping, you can check that a document still parses with the XML formatter. JSON is different: it escapes quotes with a backslash, not an entity, which the JSON formatter will flag if you get it wrong.

Watch out for double encoding. Encoding text that is already escaped turns &amp; into &amp;amp;, and readers see raw codes on the page. If a string already contains entities, decode it first, then encode it once.

Common uses

  • Showing HTML, XML or JSX code samples in a blog post or documentation page
  • Escaping user-supplied text before writing it into an HTML template by hand
  • Putting quotes safely inside an HTML attribute value
  • Decoding entity-heavy text copied from an RSS feed, API response or page source
  • Fixing a CMS field that shows &amp; or &quot; instead of the real characters

If you need to pull the text content out of a whole page rather than unescape a string, the HTML to Markdown converter strips the tags and keeps the structure. For more encoders, formatters and converters, browse all developer tools.

HTML entity terms explained

TermWhat it means
HTML entityA text code beginning with & and ending with ; that stands for one character, such as &lt; for <
Named entityAn entity that uses a name, such as &amp;, &copy; or &nbsp;
Numeric character referenceAn entity that uses the Unicode code point, in decimal (&#169;) or hex (&#xA9;)
EscapingReplacing characters that have special meaning in markup so they display literally
Double encodingEncoding text that is already encoded, which turns &amp; into &amp;amp; and shows raw codes on the page
XSSCross-site scripting: injecting script through untrusted text placed in a page without proper escaping

Frequently Asked Questions

Reviewed by Raja Jahangir · Last reviewed: October 7, 2026

How do you encode HTML entities?

To encode HTML entities, paste text and the five characters that break markup are replaced: & becomes &amp;, < becomes &lt;, > becomes &gt;, double quotes become &quot;, and apostrophes become &#39;; accented letters and emoji can be encoded too. Decoding reverses any named or numeric entity, including &nbsp; and &#169;. Both run in the browser, so nothing is uploaded.

Why do you need to escape < and & in HTML?

Escaping < and & in HTML stops a browser reading them as markup. An unescaped < starts a tag, so user text like <script> would run as code, and a bare & begins an entity. Writing them as &lt; and &amp; makes the browser display the literal characters instead of interpreting them.

Sources and standards