HTML Entity Encoder and Decoder

Convert characters to HTML entities and back, from the five that matter to full numeric escaping.

Processed on your device — no upload

termiva entities --encode
0 chars

The ampersand is escaped first. Doing it in any other order encodes the entities you just produced a second time, turning < into < — which is why text sometimes shows up on a page with the tags visible.

Minimal is what you want almost always. Modern pages are served as UTF-8, so Arabic, accents and emoji need no escaping at all — escaping them makes the file larger and much harder to edit.

0 chars
direction encodein 0 charsout 0 charsnothing uploaded

How to use it

  1. Choose encode or decode.
  2. Paste your text.
  3. Copy the result.

How it works

An entity is a way of writing a character that would otherwise be read as markup. &lt; puts a literal < on the page instead of starting a tag. There are three forms: named (&amp;), decimal (&#38;) and hexadecimal (&#x26;), and they mean exactly the same thing.

Only five characters genuinely need escaping in modern HTML: &, <, >, and both kinds of quote inside attribute values. Everything else — Arabic, accents, emoji, dashes — is served perfectly well as UTF-8, and escaping it makes the file larger and much harder to edit.

Order matters, and getting it wrong is the classic bug. The ampersand has to be escaped first. Do < first and the & in the &lt; you just produced gets escaped in the second pass, giving &amp;lt; — which displays on the page as the literal text &lt;. That is what has happened whenever you see raw entity codes in a heading on a live site.

Decoding accepts all three forms and leaves anything it does not recognise exactly as it was, rather than silently dropping it. A stray & in prose is not a broken entity and should not be touched.

A worked example

The case this is really for: showing code on a page. You want a visitor to read <a href="?a=1&b=2"> rather than have the browser render a link. Paste it, encode with the minimal setting, and put the result inside your <pre>. Every documentation site does this, and doing it by hand is where the missing escape gets in.

The security note, stated precisely. Escaping is what stops user input from becoming markup — a comment containing <script> is inert once escaped. But this is not an XSS defence you can rely on by pasting text through a web page. Escape at the point of output, in your template engine, automatically, for every value. A manual pass through any tool covers the one string you remembered.

Attribute values need their quotes escaped too. title="5" wide" ends at the second quote, and the rest becomes stray attributes. This is the mechanism behind a meta description that mysteriously stops at an apostrophe — the meta tag generator escapes automatically for that reason.

When to use the numeric setting. Almost never — but if a file may be served without a charset declaration, or is going into a system that mangles anything above ASCII, escaping every non-ASCII character numerically survives it. Load the decode sample: &#1605;&#1585;&#1581;&#1576;&#1575; is مرحبا, five Arabic letters written as five decimal code points.

If what you are escaping is a URL rather than markup, the URL encoder is the right tool — percent encoding and entities are not interchangeable.

Questions

How do I escape special characters in HTML?

Encode them and the five that carry meaning become entities. Decoding does the reverse, so you can unescape text that arrived with &amp;lt; showing on the page.

Which characters do I have to escape?

In text content, & < and >. Inside attribute values, also the quote character you used. Everything else is fine as UTF-8.

Do I need to escape Arabic, accents or emoji?

No. Any page served as UTF-8 handles them directly. Escaping them makes the file bigger and much harder to read or edit.

Why do I see &amp;lt; on my page?

The text was escaped twice — the ampersand of the first entity got escaped by the second pass. Escape the ampersand first, and only once.

Is escaping enough to prevent XSS?

Escaping on output is the core defence, but it has to happen automatically in your templates for every value. Running one string through a web page is not a security strategy.

What is &nbsp; for?

A space that does not break onto a new line — useful between a number and its unit. Used for indentation or spacing it is a layout hack that CSS does better.

What is the difference from URL encoding?

Entities are for HTML; percent encoding is for URLs. A URL inside an HTML attribute may need both, applied in that order.

Does decoding handle hex entities?

Yes — named, decimal and hexadecimal forms all decode. Anything unrecognised is left untouched rather than removed.

Is my text sent anywhere?

No. It is converted in this page, which matters when the text is unpublished content or a template with real data in it.