HTML Entity Encoder / Decoder
Paste text or HTML to escape its special characters as entities, or switch to Decode to turn entities such as < and é back into characters.
Encoded
Entity names this page understands
| Character | Name | Decimal | Hex |
|---|
This tool runs in your browser. Nothing you type is uploaded or saved, and there is nothing to install or sign up for.
What an HTML entity is and when you need one
A browser reads a web page as a mix of text and tags. A tag starts with a less-than sign, and special codes start with an ampersand. That raises a problem: what if you want to show a less-than sign, or print a snippet of code on the page, without the browser treating it as a real tag? The answer is an entity, a short code that stands in for one character. The browser sees < and draws a less-than sign instead of starting a tag.
This tool writes those codes for you. Encode takes ordinary text or HTML and escapes the characters that would confuse a browser. Decode goes the other way and turns entities back into the characters they stand for, which is handy when copied text arrives full of codes such as & and '.
How to escape or unescape text
- Choose Encode or Decode under Direction.
- Paste into the Text or HTML box. The result shows up at once.
- When encoding, pick the Style for the five special characters: short names, or numbers for every one.
- Decide what happens to Accents, symbols and emoji. They can stay as they are, or become decimal or hex number codes.
- Press Copy result. Use result as input runs the answer back through the opposite direction, and Reset restores the sample.
The three tiles count what was changed, and the table at the bottom lists every entity name the decoder recognizes.
Worked example: a paragraph tag with an ampersand
The page opens with this line of HTML, 46 characters long:
<p class="note">Tom & Jerry's café — 5 > 3</p>
With the default settings the encoded result is:
<p class="note">Tom & Jerry's café — 5 > 3</p>
Nine entities were written: one ampersand, two less-than signs, three greater-than signs, two double quotes and one apostrophe. The text grew from 46 to 79 characters. Paste the result into a web page and visitors see the original line, tags and all, as plain text.
The accented letter and the long dash were left alone because the third setting was on Leave as they are. Change it to Decimal numbers and those two become é and —, for eleven entities in total. With Hex numbers they are written é and —.
The five characters that always matter
| Character | Named entity | Number code | Why it is escaped |
|---|---|---|---|
| & | & | & | Starts every entity |
| < | < | < | Opens a tag |
| > | > | > | Closes a tag |
| double quote | " | " | Ends an attribute value |
| apostrophe | ' | ' | Ends a single-quoted attribute value |
The apostrophe is always written as the number code ' here, even in the names style. A named form exists and the decoder accepts it, but the number code is the one that has worked in the widest range of software, so it is the safer thing to output.
How the encoder and decoder work
Encoding is a simple walk through the text, one character at a time. Each of the five special characters is swapped for its entity. Any character above code 127, which covers accents, currency signs, symbols and emoji, is either kept or swapped for a number code built from its Unicode code point. Everything else passes through unchanged. A smiling-face emoji has the code point 128512, so it becomes 😀 in decimal or 😀 in hex.
Decoding looks for the pattern of an ampersand, a name or a number, and a semicolon. Number codes are converted straight to the matching character. Names are looked up in a table of 30 common entities, shown under the tool, such as ©, €, — and . The lookup is done with a plain table in the script. Your text is never run as HTML, so pasting a page full of tags and scripts here cannot make anything execute.
Limits and mistakes to watch for
- Names outside the table. HTML has far more named entities than the 30 this page knows. An unknown name is left exactly as typed and listed in the Left unchanged row, so you can see what was skipped. Number codes always decode.
- Double encoding. Encoding text that is already encoded turns
<into&lt;, and the page then shows the code instead of the character. Decode once and check before you encode again. - Missing semicolons. The decoder only converts entities that end with a semicolon.
- Wrong tool for the job. Entities protect text inside a web page. Text going into a link needs percent codes from the URL encoder, and data inside JSON has its own escaping rules, which the JSON formatter will check for you.
- Not a security filter. Escaping is one part of displaying untrusted text safely, but this page is a converter for people, not a replacement for the escaping built into a web framework.
Decoding uses each entity once. The text &lt; decodes to <, not all the way to a less-than sign. Decode a second time if the text was encoded twice.
Where this helps in class and on a website
Teachers writing a coding lesson can paste a snippet, encode it, and drop the result into a blog post or a learning platform so students see the tags instead of the rendered output. Students building a first web page can use it to show a math statement like 5 > 3 or a company name with an ampersand without breaking the page. If you write in Markdown, the Markdown to HTML converter escapes code blocks for you as part of the conversion.
When you clean up text copied from a web page source, decode it here first, then tidy the spacing with the extra space remover. Other converters for web work are grouped with the tech tools, and the complete list of calculators and classroom tools is one click away.
Frequently asked questions
What is the HTML entity for the less-than sign?
It is written as an ampersand, the letters lt and a semicolon. The number form is ampersand, hash, 60 and a semicolon. Both make a browser show the sign instead of starting a tag.
Which characters must be escaped in HTML?
The ampersand and the less-than sign always need escaping in page text. The greater-than sign, the double quote and the apostrophe are escaped too, because quotes can end an attribute value. This tool escapes all five.
What is the difference between named and numeric entities?
A named entity uses a short word, such as copy for the copyright sign. A numeric entity uses the character’s Unicode number in decimal or hex. Every character has a numeric form, but only some have a name.
Do I need to encode accented letters and emoji?
Usually not. A page saved and served as UTF-8 can hold them directly. Encoding them as numbers is useful when a system only accepts plain ASCII text.
Why does my page show the entity code instead of the character?
The text was probably encoded twice, so the ampersand at the start of the entity was itself escaped. Decode the text once and paste it again.
Is it safe to paste HTML with scripts into this tool?
Yes. The text is handled as plain characters and looked up in a table. It is never inserted into the page as HTML, so nothing in it can run.
