HTML Encoder & Decoder

Convert HTML special characters to entities and back again.

HTML Encoder & Decoder tool

Direction

About the HTML Encoder & Decoder

Angle brackets, ampersands and quotes have special meaning in HTML, so code samples and user-supplied text must be escaped before they are displayed, or the browser will treat them as markup. This tool will HTML encode text, turning < into &lt; and & into &amp;, so a snippet of code appears exactly as written on a web page, and it decodes entities back into ordinary characters. Escaping user input is also a basic defense against cross-site scripting. Everything runs in your browser. For URLs, use the URL Encoder, and for showing code in Markdown, the Markdown to HTML converter escapes raw HTML automatically.

Encoding is the direction that protects people. Whatever a visitor types into a comment box or a profile field must be escaped before it appears inside a page, or a submitted script tag will execute in other visitors' browsers. That class of bug is called cross-site scripting, and escaping output is the standard first defence against it. Encode mode lets you see precisely how a value should look once it has been made safe.

Decoding is the direction you will probably use most days. Text taken from RSS feeds, spreadsheet exports and old databases often still contains entities, so a headline turns up reading Fish &amp; Chips. Decode mode turns every entity back into its character, whether it is written by name, such as &copy;, or by number in decimal or hexadecimal. Encoding user input before it is shown on a page is also one of the basic defences against cross-site scripting attacks.

How to use the HTML Encoder & Decoder

  1. Choose the directionEncode turns special characters into entities; Decode turns entities back into characters.
  2. Paste your textAdd the markup, code sample or plain text you want to convert, from a single word to a full page of HTML.
  3. Check the outputThe result changes as you type or switch direction, so you can compare the two forms side by side.
  4. Copy the resultUse the copy button to take the converted text.

HTML Encoder & Decoder features

  • Converts < > & and both quote marks, with an option to convert everything outside plain ASCII
  • Understands named entities such as &nbsp; and &copy;
  • Reads numeric entities in both decimal and hexadecimal
  • Switch direction without retyping anything
  • Results that update while you type
  • One-click copy

Common uses

  • Making visitor comments safe before they are shown on a page
  • Displaying a code example inside an article without it rendering
  • Removing leftover entities from text exported out of a CMS
  • Preparing copy for an HTML email template
  • Seeing exactly what a value becomes once it is escaped

HTML entities in practice: showing code on a blog, dangerous links, template escaping, curly quotes in shares, non-breaking spaces and RSS

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

Entities let a page show characters that would otherwise be treated as markup, and decoding turns stray entities in exported content back into readable text. This guide encodes a code sample for a tutorial post, then covers the link values that entity encoding does not make safe, how template engines escape for you, the curly quotes that appear as numbers in social shares, useful entities such as the non-breaking space and why some entities break RSS feeds.

A worked example: showing code on a blog

A tutorial post needs to display the line <button onclick="buy()">Buy</button> as text rather than as a working button. Encoded, it becomes &lt;button onclick=&quot;buy()&quot;&gt;Buy&lt;/button&gt;. Placed inside pre and code elements, the encoded version displays exactly as written, while the original would have rendered a real button in the middle of the article.

Links that encoding does not fix

Encoding protects text placed between tags and inside quoted attributes, but a link address is a special case. A user-supplied value such as javascript:alert(1) contains no characters that need encoding, so it passes through unchanged and runs when the link is clicked. Values used as link addresses must also be checked to start with http or https before being placed in an href.

Template engines escape for you

Modern template systems, including Blade, Twig, Django templates and React, escape output automatically when values are inserted the normal way. Problems arise when developers use the raw-output options, such as Blade's unescaped output syntax or React's dangerouslySetInnerHTML, to display formatted content. Reserve these for trusted HTML that has been sanitised, never for raw user input.

Curly quotes in social shares

WordPress converts straight apostrophes in titles into curly ones and stores them as numeric entities, so a title can appear in feeds and share previews as Ayesha&#8217;s Kitchen. Decoding shows that &#8217; is simply a right single quotation mark. The fix belongs in whichever plugin or tool outputs the title without decoding it first.

Non-breaking spaces

The entity &nbsp; inserts a space that never breaks across lines, which keeps short combinations together, such as Rs 500, 10 kg or a person's initials and surname. Using it for layout, with rows of non-breaking spaces to push text sideways, is fragile; CSS margins and padding do that job properly.

Entities in feeds and XML

XML recognises only five named entities: those for less-than, greater-than, ampersand, double quote and apostrophe. HTML entities such as &nbsp; or &copy; are undefined in XML, so a feed containing them fails to parse in strict readers. Using the actual characters, or numeric entities such as &#160;, keeps RSS feeds and sitemaps valid.

Double-encoded text

Text showing &amp;amp; or &amp;quot; has been encoded twice, typically once when saved and again when displayed. Decoding once reveals the intended text, but the lasting fix is to store text in its original form and encode only once, at the moment it is placed into HTML.

Encoding in code

In JavaScript, setting an element's textContent instead of innerHTML inserts text safely without manual encoding. In PHP, htmlspecialchars with the ENT_QUOTES flag and UTF-8 encoding covers text and attribute contexts. In Python, html.escape does the same. Using these built-in functions is safer than writing your own replacement rules.

Email subjects and plain text

Entities belong in HTML only. Subjects, SMS messages and plain-text emails show entities literally, so a subject reading Tom &amp; Jerry means HTML-encoded text was sent to a plain-text field. Decode values before sending them anywhere that is not HTML.

Common mistakes

  • Trusting entity encoding to make link addresses safe.
  • Using raw-output template features for user content.
  • Using HTML-only entities in XML feeds.
  • Encoding text before storing it and again when displaying it.

Related tools

To encode values for links, use URL Encoder. For text inside JSON, try JSON Escape, and to check feeds parse correctly, XML Formatter.

Always quote attributes

An attribute value without quotes ends at the first space, so a user-supplied value containing a space can add new attributes to an element. Always wrap attribute values in double quotes and encode any double quotes inside them. This single habit closes a whole class of injection problems that encoding alone cannot.

Text pasted from word processors

Text copied from Word or Google Docs brings curly quotes, long dashes and special spaces. On a UTF-8 page these characters display correctly without any entities; only the reserved characters, such as angle brackets and ampersands, need encoding. Converting everything into entities makes the source harder to read without any benefit.

Search engines read entities as characters

Search engines decode entities before indexing, so é written directly and é written as an entity are treated the same. There is no ranking benefit either way. Choose the form that keeps your source readable, which on modern UTF-8 sites means writing characters directly.

Privacy

Encoding and decoding run in your browser. Nothing you paste is uploaded or stored.

Frequently asked questions

Which characters always need escaping?

In ordinary text, the & sign and the < and > signs; inside attribute values, the " and ' marks as well. Escaping those five handles the cases that break layouts or open security holes.

Is escaping HTML enough to make a site secure?

It closes one important type of hole, but the right escaping depends on where the text goes. Text that lands inside JavaScript, CSS or an href follows different rules again, so treat HTML escaping as one essential layer among several, not as a complete security plan.

How do named and numeric entities differ?

Named entities such as &copy; are easy to read but exist only for a fixed list of characters. Numeric entities such as &#169; or &#xA9; can represent any character by its code number. The decoder handles all three forms.

Why do I still see &amp; after decoding?

The text was most likely escaped twice, so the ampersand at the start of each entity was itself turned into an entity. Run the decoder a second time and the remaining entities will resolve.

Should accented letters be turned into entities?

Usually there is no need. Pages served as UTF-8 show accented and non-Latin letters directly. The option to encode every non-ASCII character exists for older systems that cannot cope with anything beyond basic English characters.

Is my text uploaded anywhere?

No. The conversion is done inside this page using your browser's own HTML parser, so nothing you paste is transmitted, logged or stored on any server.