Free Handy Tools

HTML Entity Converter

Result

Nothing to convert yet.

The five that are not optional

  • &&  &Starts every reference, so an unescaped one can swallow the text after it.
  • <&lt;  &#60;Starts a tag. This is the one that turns text into markup.
  • >&gt;  &#62;Ends a tag. Safe in text in practice, escaped by convention and by every serialiser.
  • "&quot;  &#34;Ends a double-quoted attribute value early.
  • '&apos;  &#39;Ends a single-quoted attribute value early. &apos; is HTML5 and XML; older HTML4 parsers want &#39;.

Which of the five you need depends on where the text lands. In a text node, & and < are the only ones that can change the meaning. Inside a double-quoted attribute you also need "; inside a single-quoted one you need the apostrophe instead. Leave an attribute unquoted and the list grows to include spaces, backticks and equals signs, which is why unquoted attributes are a bad habit rather than a shortcut.

Escaping is not a substitute for context. Entities do nothing at all inside a <script> or <style> block — those elements have their own parsing rules, so an escaped quotation mark there stays the literal six characters. A URL in an href needs per-cent encoding, not entities. Use your template language’s own escaping for anything user-submitted; this tool is for hand-editing markup, not for sanitising input.

Decoding is done from a table of 150 named references rather than by handing the text to the browser to parse, so nothing here can execute and a broken reference is reported instead of being quietly repaired. The full HTML5 list runs past 2,200 names; the ones missing from this table are the rare mathematical variants, and numeric references cover every character regardless.

Five characters that matter and two thousand that do not

HTML lets every character be written as a reference, and almost none of them need it. The exceptions are the ones a parser acts on: an ampersand, a less-than sign, a greater-than sign and the two quotation marks. Escape those and text stays text. The dashes, arrows, accented letters and card suits are a typing convenience, not a safety measure.

This converter goes both ways: the five alone, a name for every character that has one, or decimal or hexadecimal references throughout — and it reads all three forms back to plain text.

Which escape belongs in which position

The right answer depends on where the text lands, and the differences are not stylistic.

  • In ordinary text between tags, only the ampersand and the less-than sign can change the meaning; the greater-than sign is escaped by convention, which is harmless and worth keeping.
  • Inside a double-quoted attribute you need the ampersand and the double quote. Inside a single-quoted one you need the ampersand and the apostrophe instead.
  • In an unquoted attribute the dangerous list grows to include spaces, tabs, backticks, equals signs and both angle brackets — the real argument for always quoting attributes.
  • Inside a script or style element, references do nothing at all. Those elements have their own parsing rules, so an escaped quotation mark stays six literal characters and breaks your JavaScript.
  • A URL in an href needs percent-encoding for its own characters, while entities handle the ampersands between query parameters — which is why a correct link often contains both.

One character, three ways to write it

An em dash can be written as &mdash;, &#8212; or &#x2014; — a name, the decimal code point, and the same number in hexadecimal. All three give the identical character, and the numeric forms always work because they need no name to exist. É is &Eacute;, &#201; or &#xC9;.

Above the basic plane there are no names, so an emoji must be numeric: 🎉 is &#x1F389; or &#127881;. This tool writes one reference by working in code points. Tools stepping through UTF-16 code units emit the surrogate halves &#55356; and &#57225;, which no parser can reassemble — the usual reason an emoji renders as two question marks.

The semicolon is not optional. HTML forgives a missing one for a few legacy names, so &nbsp10 sometimes works, but XML and most template engines reject it, and the decoder flags it rather than repairing it.

Double-escaping, and how to recognise it

When a page displays &amp;amp;, or shows &lt;b&gt; as text instead of bold, something escaped text that was already escaped. It happens when a framework escapes output automatically and the value handed to it was escaped once already on its way into storage.

The fix is to escape exactly once, at the point of output, and to store the original characters. The mechanism is visible here: put &amp; in and it returns &amp;amp;, because the ampersand starting that reference is itself a character needing an escape. Each decode peels off one layer.

When you genuinely need a reference

On a page served as UTF-8, accented letters, currency symbols and emoji can be typed directly. References earn their place for characters that are invisible or ambiguous in a source file: a non-breaking space, a zero-width joiner, a soft hyphen.

They matter in XML too, where only five names are predefined and the rest must be numeric. A footnote: &apos; is valid in HTML5 and XML but not in HTML 4, so &#39; is the safer apostrophe if anything ancient might read the document.

Decoding is done from a table rather than by letting the browser parse the input, so nothing in the text can execute and a malformed reference is reported instead of corrected. Nothing is uploaded — this is arithmetic on a string, done on your own machine.

Accents, &nbsp;, and double escaping

Do I still need to escape accented letters?

No, provided the page declares UTF-8 and the file is saved that way. Writing &eacute; instead of é makes the source harder to read and to search, for nothing. The exception is a system that mangles non-ASCII in its pipeline.

Why does &nbsp; behave differently from a space?

Because it refuses to break. A line will not wrap at a non-breaking space and consecutive ones do not collapse, which makes it useful between a number and its unit, and a poor way to indent or space out a layout.

Does escaping stop cross-site scripting?

Only in the context it was chosen for. HTML escaping does nothing inside a script block, inside a URL, or in an unquoted attribute, so a value placed there stays exploitable. Let your template engine escape for the context rather than assembling markup from strings.

Which form should I use when I do need a reference?

A name where a well-known one exists, because &mdash; is readable and &#8212; is not. Hexadecimal suits anything you look up in a Unicode chart, since charts list code points that way.

How does a character reference differ from a \u escape?

By audience. &#x2014; is read by an HTML parser, \u2014 by a JavaScript or JSON parser, and U+2014 is how a standards document names the code point. Put one where another is expected and it stays on the page as literal text.

Why does my page show  before every non-breaking space?

That is UTF-8 being read as Latin-1: the two bytes of a non-breaking space, C2 A0, render as an  followed by a space. The fix belongs at the encoding declaration — escaping the characters afterwards only freezes the mistake into the file.

What is a soft hyphen for?

It marks a place inside a long word where the line may break, and shows nothing when it does not. Written as &shy; precisely because typing the character leaves nothing visible in the source for the next person to find.