Skip to content

Text for markup, not a rendered preview

HTML entity encode and decode

Browsers treat < as the start of a tag. If the characters are meant to be seen, the HTML source needs &lt; instead. This page writes that source. It does not render it.

Encoding replaces & < > " and '. The ampersand is replaced first in spirit: a raw & becomes &amp;, so the escape cannot be read as an entity of its own. Decoding understands the named set used here, plus decimal &#39; and hexadecimal &#x27;. Unknown names are left as you typed them. There is no preview pane, because showing the decoded string as HTML would run any markup you pasted.

The source stays in this tab. Nothing is posted, and nothing is inserted into the page as HTML.

This tool runs in your browser. Turn on JavaScript to use it.

A tag written as text

The result is what you put in an HTML file when the reader should see the tag, not a paragraph.

Characters
<p class="x">
Entities
&lt;p class=&quot;x&quot;&gt;
Apostrophe
&#39;

How to use it

  1. 1Paste the characters you want to show, or the entities you want to read.
  2. 2Encode before you drop the text into HTML. Decode when you already have entities from source.
  3. 3Copy the result into your editor. This page will not paint it as a live element.

Good to know

  • Quotes become &quot; and apostrophes become &#39;, so the text is safe in a double-quoted attribute too.
  • Numeric entities may point at any Unicode scalar. A code point past U+10FFFF is left unchanged.
  • &nbsp;, &copy;, &mdash;, and a short list of other names decode. Obscure names are not a full HTML catalog.

Questions

Why is there no preview?

A preview that parses HTML would treat the input as markup. The result box shows the characters only.

Do I encode an entire document?

Only the text nodes and attribute values that came from outside. Encoding the tags themselves would show the tags instead of using them.

Is &amp;amp; a double escape?

Yes. Encoding twice turns an ampersand into &amp;amp;. Decode once to step back.

Related tools

  • Inspect Unicode code points

    A character you see may be one code point or several. This page lists the first 80 code points, with U+ notation, decimal, UTF-8 bytes, and a JavaScript escape.

  • Format XML

    A long XML line is hard to read. This page indents elements by two spaces, or removes the indent. It does not try to repair a broken tag.

  • URL encode and decode

    Reserved characters in a URL have jobs. A space, an ampersand, or an equals sign inside a value must be escaped or the query will split in the wrong place.