An HTML entity encoder replaces characters that have a special meaning in HTML with safe codes that browsers display as ordinary text. If you want a page to show an actual angle bracket or an ampersand, you can't simply type it, because the browser may read it as markup. Paste your text into this HTML entity encoder, and it escapes those characters for you. Switch to Decode to do the reverse, so that a string full of codes such as & becomes readable again. Everything is handled in your browser, and nothing that you paste is sent to our server.
How to use the HTML entity encoder
- Choose Encode or Decode.
- Paste your text.
- Tick the box if you'd like every non-ASCII character encoded too.
- Press Convert and copy the result.
What is an HTML entity?
In HTML and XML, a character can appear directly, or it can be represented by a series of characters called a character reference. There are two types. A numeric character reference refers to a character by its Unicode code point, in the form &#nnn; for decimal or &#xhhhh; for hexadecimal. A character entity reference uses a name instead, such as © for the copyright sign.
The five characters to escape
| Character | Entity | Why it matters |
|---|---|---|
| & | & | Starts an entity |
| < | < | Starts a tag |
| > | > | Ends a tag |
| " | " | Ends a double-quoted attribute |
| ' | ' | Ends a single-quoted attribute |
A worked example
Suppose that you're writing a tutorial and you want your page to display the tag <b>bold</b> as text. If you paste it directly, the browser makes the word bold and hides the tags. Run it through the encoder, and you get <b>bold</b>. When you put that into your page, the visitor sees the tag exactly as you intended. The word café can be left as it is in most modern pages, but if you tick the non-ASCII option, it becomes café.
Why encoding matters for security
Encoding also has a security role. When a website displays something that a visitor typed, such as a comment, it needs to escape the text first. Otherwise, a person could submit markup or a script that runs in other visitors' browsers, which is known as cross-site scripting. Modern frameworks do this automatically in most cases, but it's worth understanding what's happening. Use this page to check how a piece of text will look once it's been escaped, and remember that a real application must escape output on the server or in its templates, every time.
Named and numeric entities
Named entities are easier to read, while numeric references cover every character in Unicode. For example, the euro sign can be written as € or as € and the two give the same result. The decoder here understands numeric references of both kinds, as well as the names of common symbols and accented Latin letters. A rarely used name that it doesn't recognize is left unchanged, so that nothing is lost.
When you need the non-ASCII option
Most web pages today use UTF-8, which can represent characters such as é, € and 你 directly, so you usually don't need to encode them. The option is useful in older systems, in some email templates, or when a file is being passed through software that can't be trusted to preserve its encoding. It turns each of those characters into a numeric reference that uses only plain ASCII.
Encoding, escaping and encryption
These terms can be confused. HTML encoding only changes how characters are written, and anyone can reverse it, so it doesn't hide anything. URL encoding is a separate scheme that's used in web addresses, where a space becomes %20. Encryption is a different thing altogether, as it needs a key to reverse. If you need to keep something secret, use a proper encryption tool instead of an encoder.
Double encoding
A common bug is encoding text twice. If an ampersand is encoded once, it's written as &. If that result is encoded again, it becomes &amp;, and your readers will see stray codes on the page. If your text already contains entities, decode it first and then encode it once.
Pasting code into a blog or forum
Many editors treat pasted code as real markup. Encoding it first ensures that readers see the code itself, instead of the effect that it has on the page.
Common mistakes
- Forgetting the ampersand. It has to be escaped as well.
- Encoding twice. Stray codes will show on the page.
- Treating encoding as security on its own. Applications still need proper output handling.
Related developer tools
Tidy your markup with the HTML formatter, escape web addresses with the URL encoder and decoder, and convert data with the Base64 encoder and decoder.
What next
Use this often? Add HTML Entity to your Home screen.
Frequently asked questions
How does the HTML entity encoder work?
It replaces characters such as ampersands and angle brackets with entity codes that browsers display as text.
How do I decode HTML entities?
Choose Decode, paste your text and press Convert.
Which characters should I escape in HTML?
The ampersand, less-than and greater-than signs, and both kinds of quotation mark.
Is HTML encoding the same as encryption?
No. Anyone can reverse it, so it doesn't hide anything.
Is my text uploaded?
No. The conversion happens in your browser.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.