HTML Entity Encoder & Decoder

Paste HTML or text containing special characters and get a version that displays literally on a web page. Decode < style entities back into characters with one click.

Loading HTML Entity Encoder & Decoder…

How to Use HTML Entity Encoder

1

Paste the HTML or text

Enter a snippet of markup you want to show as text, or a string that may contain characters such as < and &.

2

Encode or decode

Press Encode HTML to escape special characters as entities, or Decode HTML to turn entities such as &lt; and &#39; back into the characters they represent.

3

Check the output

After encoding, the snippet will display as literal text in a page instead of being parsed as tags.

4

Copy it into your page or template

Copy the escaped output into a blog post, documentation page or code sample.

HTML Entity Encoder Guide

Why HTML needs escaping

Browsers treat <, > and & as the start of markup. To show them as text, for example in a code sample, blog post or documentation page, they have to be written as the entities &lt;, &gt; and &amp;. Inside attribute values, quotes need escaping too, as &quot; and &#39;.

Escaping is also a core defense against cross-site scripting (XSS). Any user-supplied text placed into HTML should be escaped, so a comment containing <script> is displayed rather than run. Template engines do this automatically; this tool is for the cases where you are writing HTML by hand.

Decoding entities

Decoding turns entities back into characters, which is useful when text copied from page source, an RSS feed or an API response is full of &amp; and &quot;. Run decode once per level: text that was escaped twice shows &amp;lt; and needs two passes.

Frequently Asked Questions

Which characters must be escaped in HTML?

In text content, always escape & and <. Inside attribute values, also escape the quote character that wraps the attribute, " or '. Escaping > is not strictly required but is common and harmless. Everything else, including accented letters and emoji, can be written directly when the page uses UTF-8.

Does escaping HTML prevent cross-site scripting?

Escaping is the main defense when user input is placed in HTML text or attributes, but it has to match the context. Text inside a script block, a URL in an href, or a CSS value each need different handling. Templating systems such as React and most server frameworks escape text automatically, so use them rather than building HTML strings by hand.

What is the difference between named and numeric entities?

Named entities such as &copy; are easier to read, while numeric entities such as &#169; or &#xA9; work for any Unicode character, including ones with no name. Browsers treat them the same way.

Why does my page show &lt; instead of a < sign?

The text was escaped twice. The first pass turned < into &lt;, and the second turned the & in that entity into &amp;, so the source contains &amp;lt; and the browser displays &lt;. Decode once to get back to the right value, and make sure only one step in your pipeline does the escaping.

Do I need entities for accented letters and emoji?

Not on a page served as UTF-8, which almost every modern site is. You can write é, ñ or an emoji directly in the HTML. Entities for these characters are only needed when a system in your pipeline cannot handle UTF-8, such as some older email tools.

Related Guides

More in Developer Utilities