Skip to content
ToolPlankDEV
Encoders & Decoders
100% In-Browser Execution

Updated:

HTML Encode Online

HTML encode any text so it is safe to paste into a page, a template or a code sample. The tool escapes &, <, > and quotes, and can also turn accents, symbols and emoji into named, decimal or hex entities. It runs in your browser, so nothing is uploaded.

Options:

Only used when non-ASCII characters are encoded

Text or HTML to encode

Input
0 chars · 0 lines

Encoded text

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Characters encoded

Each character the tool replaces is listed here with a count.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use HTML Encoder

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste the text or code

    Paste the text you want to show on a page, put in an attribute or place inside a template. It can be plain text, a snippet of HTML or a whole document.

  2. 02

    Choose what to encode

    The default encodes only the characters that HTML treats as markup: &, <, > and quotes. Switch to Also all non-ASCII characters to turn accents, symbols and emoji into entities, then pick named, decimal or hex.

  3. 03

    Copy the encoded text

    The result updates as you type, with a list of every character that was replaced. Press Copy, or press the swap button to turn the entities back into text with HTML Decoder.

What it means to HTML encode text

To HTML encode text is to replace characters that have a special meaning in HTML with entities, so the browser shows them instead of acting on them. A less-than sign becomes &lt;, an ampersand becomes &amp; and a double quote becomes &quot;.

You need it whenever text that is not markup has to sit inside markup. A code sample in a blog post, a user's comment in a template, a title inside an attribute and an example in documentation all break the page if a stray < or & gets through. The reverse is HTML Decoder.

A worked example

A line of HTML and a sentence with quotes:

HTML
<a href="/menu?item=crème&size=large">Café & Bar — 5 €</a>
She said "hi" and it's 1 < 2 > 0 😀

With the default settings, only the markup characters change:

Text
&lt;a href=&quot;/menu?item=crème&amp;size=large&quot;&gt;Café &amp; Bar — 5 €&lt;/a&gt;
She said &quot;hi&quot; and it&#39;s 1 &lt; 2 &gt; 0 😀

Choose Also all non-ASCII characters with the named style and the accents, the dash, the euro sign and the emoji change too:

Text
&lt;a href=&quot;/menu?item=cr&egrave;me&amp;size=large&quot;&gt;Caf&eacute; &amp; Bar &mdash; 5 &euro;&lt;/a&gt;
She said &quot;hi&quot; and it&#39;s 1 &lt; 2 &gt; 0 &#128512;

The emoji has no common name, so it falls back to a decimal code. The hex style would give &#x1F600; instead.

The options explained

  • What to encode: markup characters only is enough for any page served as UTF-8. Encoding all non-ASCII characters produces pure ASCII output, which survives systems that mangle accents or emoji.
  • Style: named writes &eacute; when a common name exists and falls back to a number for everything else. Decimal writes &#233; and hex writes &#xE9;. All three decode to the same character.
  • Encode quotes: turns " into &quot; and ' into &#39;. Required inside attribute values, optional in plain text between tags.
  • Leave existing entities alone: keeps an entity that is already written, such as &amp; or &#169;, instead of encoding its ampersand a second time.

The apostrophe uses &#39; rather than &apos;. Both work in HTML5, but &apos; is not valid in HTML 4, so the numeric form is the safe one.

Avoid double encoding with existing entities

Encoding text that is already encoded turns &amp; into &amp;amp;, and the reader sees the literal characters &amp; on the page. That is the usual cause of the stray codes people notice in titles and descriptions.

Tick Leave existing entities alone when the text is a mix of raw characters and entities. A valid entity, either a numeric code or a name from the HTML5 list followed by a semicolon, is kept as it is. A lone ampersand and a made-up name such as &bogus; are still encoded. If the text is already entirely encoded, do not run it again at all.

When to encode and when not to

  • Do encode text you want shown literally: code samples, user input, example markup and email template text.
  • Do encode values that go inside an HTML attribute, with quotes on.
  • Do not encode a whole HTML document you want the browser to render. Every tag would turn into visible text.
  • Do not use it for URLs. A web address needs percent-encoding, so use URL Encode.
  • Do not use it for text going inside JSON. That needs backslash escapes, which JSON Escape handles.

HTML escape in code

A template engine escapes output for you in most frameworks. When you have to do it by hand, use a library function instead of a regular expression. In Python:

Python
import html
html.escape("Tom & Jerry's <b>", quote=True)

In PHP, htmlspecialchars($text, ENT_QUOTES) covers the same five characters, which is the job people search for as htmlspecialchars encode. This page is for one-off jobs and for checking what the right output should look like.

Limits of this tool

  • Named style uses a set of common names, such as &eacute;, &mdash; and &euro;. Characters without one get a decimal code rather than an obscure name.
  • Characters outside the basic range, such as emoji, are encoded as one code point, not as two surrogate halves. A broken half of a pair becomes the replacement character &#65533;.
  • Line breaks and tabs are kept as they are. The tool never adds <br> tags.

Encoding runs in your browser. What you paste is not uploaded or stored. See the Privacy Policy for details.

Frequently Asked Questions

Technical Q&A for HTML Encoder

Common questions about edge cases, character encoding, and privacy guarantees.

Paste the text into the left box. The encoded version appears on the right as you type, ready to copy. By default it replaces &, <, > and quotes.

At minimum, & < > and the two quote characters. That is the same set htmlspecialchars covers. With the non-ASCII option on, accents, symbols and emoji are replaced too.

None in practice. Both mean replacing special characters with entities. Python calls the function html.escape and PHP calls it htmlspecialchars.

Not if your page is served as UTF-8, which is the normal case. Encode them when the text passes through a system that corrupts accents or emoji, or when you need plain ASCII output.

They decode to the same character, so it is a matter of taste. Named entities are the easiest to read, decimal is the most widely supported and hex matches Unicode tables.

&#39; works in every version of HTML, while &apos; is not valid in HTML 4. The numeric form is the safe choice.

Tick Leave existing entities alone. Valid entities such as &amp; and &#169; are kept, and only stray ampersands are encoded.

You can, but the browser will then show the markup as text instead of rendering it. Encode a page only when you want to display its source, for example in a tutorial.

It prevents text from being read as markup in the places where it is shown as page content or in a quoted attribute. It does not cover scripts, styles or URLs, which need their own escaping.

Use the HTML Decoder, one click away with the swap button. It knows every named HTML5 entity and can fix text that was encoded twice.