🔤 HTML Entity Encoder / Decoder

Encode and decode HTML entities with a full reference table, plus why entity encoding alone is not safe inside script blocks, URLs or CSS.

Free No Signup Required Browser-Based

Result

What HTML Entity Encoder / Decoder Does

HTML entities let you write characters that would otherwise be interpreted as markup, or that are hard to type. There are three forms: named (&), decimal (&) and hexadecimal (&). All three produce the same character.

Only five characters strictly need escaping in HTML, and which of the five depends on where the text appears. Inside ordinary text you need to handle & and <. Inside an attribute value you also need the quote character that delimits it.

The important thing this tool cannot do for you is choose the right encoding for the context. HTML entity encoding is the correct defense when text lands in HTML body content. It is not sufficient — and can be actively useless — when the same text lands inside a script block, a URL, or a CSS value.

How to Use HTML Entity Encoder / Decoder

  1. Select Encode or Decode mode
  2. Paste your raw text or HTML code into the input area
  3. View the converted safe HTML entity string and click Copy Result

The Characters That Must Be Escaped

Verified against actual Unicode code points.

CharacterNamedDecimalEscape when
&&amp;&#38;Always — and always first
<&lt;&#60;Always in body text
>&gt;&#62;Recommended, not strictly required
"&quot;&#34;Inside double-quoted attribute values
'&apos;&#39;Inside single-quoted attribute values

Entities People Actually Look Up

Including the two that get asked about most often.

CharacterNamedDecimalName
&bull;&#8226;Bullet — the &#8226 in the PAA question
'&apos;&#39;Apostrophe — the &#39 in the PAA question
&nbsp;&#160;Non-breaking space
©&copy;&#169;Copyright
®&reg;&#174;Registered trademark
&trade;&#8482;Trademark
&mdash;&#8212;Em dash
&ndash;&#8211;En dash
&euro;&#8364;Euro
½&frac12;&#189;One half

Encoding Depends on Context

The single most important thing about output encoding, and the thing simple encoders never mention. HTML-encoding text that lands in a script block does not make it safe.

Where the text landsCorrect encodingHTML entities sufficient?
HTML body textHTML entity encodingYes
HTML attribute valueHTML entity encoding, and always quote the attributeYes, if quoted
Inside a <script> blockJavaScript string escaping, or JSON serializationNo
A URL or query parameterPercent-encodingNo
A CSS valueCSS escapingNo
An unquoted attributeNothing is safe — quote the attributeNo

How to Read Your Result

Escape the ampersand first

Order matters and gets this wrong constantly. If you replace < with &lt; before replacing & with &amp;, the ampersand you just introduced gets escaped again and "<a>" becomes "&amp;lt;a>" — visible corruption. Verified: escaping & first gives the correct "&lt;a>". Always handle & before anything else.

Entity encoding is not XSS protection on its own

It is the right defense in exactly one context: HTML body text. Text inserted into a script block, a URL, an event handler attribute or a CSS value needs that context's own escaping. A value that is HTML-encoded and then written into an href can still execute a javascript: URL. Match the encoding to the destination.

Named entities are limited; numeric ones are not

HTML defines a fixed list of named entities. Anything outside it — most of Unicode — must use the numeric form. &#128512; and &#x1F600; both produce an emoji; there is no named entity for it. If you are unsure whether a name exists, the numeric form always works.

Non-breaking space is not a layout tool

&nbsp; prevents a line break and prevents whitespace collapsing, which makes it useful for keeping "10 kg" together. Using strings of them for indentation or spacing is fragile and inaccessible — screen readers may announce them, and the layout breaks at other viewport widths. Use CSS.

Limitations & Accuracy Notes

  • Encoding and decoding run in your browser; nothing is transmitted.
  • This encodes for HTML contexts. It does not perform JavaScript, URL or CSS escaping, and using its output in those contexts is not safe.
  • Decoding accepts named, decimal and hexadecimal references. Malformed references are left as literal text rather than guessed at.
  • It does not sanitize HTML. Encoding makes markup display as text; it does not strip dangerous elements from markup you intend to render. Those are different jobs and need a sanitizer.
  • Whether > must be escaped is a common argument. The HTML specification only requires it in limited cases, but escaping it is harmless and avoids the question.

Frequently Asked Questions

Why do developers encode HTML entities?
HTML entity encoding replaces reserved HTML characters (<, >, &, ", ') with entity representations to prevent browser injection and cross-site scripting (XSS).
What is the HTML entity for an ampersand and quotes?
An ampersand is &amp; (&#38;), a double quote is &quot; (&#34;), and a single apostrophe is &#39;.
Which characters must be escaped in HTML?
At minimum the ampersand, less-than and greater-than signs. Inside an attribute value, quotes must be escaped too — &quot; for double and &#39; for single. Escaping the ampersand first matters, because escaping it after the others would double-escape them.
Does escaping prevent XSS?
Context-appropriate escaping is the core defense, but the correct escaping depends on where the value lands. HTML-escaping a value that is inserted into a JavaScript string, a URL or a CSS rule does not make it safe — each context has its own rules, and a value placed inside a script tag needs a different treatment entirely.
What is the difference between a named and a numeric entity?
Named entities such as &amp; are readable; numeric ones such as &#38; or &#x26; refer to the Unicode code point directly. Numeric entities always work, whereas named ones are limited to a defined list, so anything unusual has to be numeric.
Do I need to escape accented or non-Latin characters?
Not if the page is served as UTF-8, which it should be — modern browsers render them directly. Escaping them is legacy practice from an era of uncertain encodings and mostly makes the source harder to read.
What is a non-breaking space?
&nbsp; renders as a space that will not collapse with adjacent whitespace and will not be used as a line-break point. It is useful for keeping a number and its unit together, and it is frequently pasted invisibly from word processors, where it causes layout problems that are very hard to see.
Is my input sent to a server?
No. Encoding and decoding both run in your browser.

References & Further Reading

By OnlineToolHubs Team • September 2026