In this article
Why some characters need escaping
In HTML, a few characters have special meaning: “<” starts a tag, “&” starts an entity, and quotes end attribute values. To show them as normal text you write them as entities – short codes that the browser turns back into the character.
| Character | Entity |
|---|---|
| & | & |
| < | < |
| > | > |
| " | " |
| ' | ' |
When you need it
- Showing code on a page – tutorials, documentation, blog posts about HTML.
- Text inside attributes – titles, alt text and data attributes containing quotes.
- Company names with “&” – “Smith & Sons” should be written
Smith & Sonsin HTML. - Old systems that only handle plain ASCII, such as some email templates.
How to encode or decode
- Open the HTML Entity Encoder.
- Paste your text and encode: the five special characters are always escaped.
- Optionally encode every non-ASCII character too – useful for systems that mangle accents or emoji.
- Choose named (
©), decimal (©) or hex (©) style. - Switch to decode to turn entities back into readable text, including emoji.
Escaping and security
When a website displays text that users typed – comments, names, search terms – without escaping it, an attacker can type HTML or JavaScript that runs in other visitors’ browsers. This is called cross-site scripting (XSS) and is one of the most common web vulnerabilities. Modern frameworks escape output automatically, but hand-written templates and quick scripts often forget. The rule: escape any untrusted text before inserting it into HTML.
Useful symbol entities
| Symbol | Entity |
|---|---|
| © | © |
| ® | ® |
| ™ | ™ |
| – (en dash) | – |
| non-breaking space | |
With UTF-8 pages, you can type most symbols directly; entities are only essential for the five special characters.
Showing code in a blog post
When you write a tutorial that includes HTML, encode the snippet and place it inside <pre><code> tags so line breaks and indentation are kept. In WordPress, the Code block does the escaping for you; in the Classic editor’s Text tab or in custom HTML blocks, paste the encoded version. Always preview the post to check that the code appears as text rather than being rendered.
Entities vs other encodings
HTML entities are for HTML. Web addresses use percent-encoding – see the URL Encoder. Binary data in text uses Base64. Using the wrong one is a common cause of broken links and garbled text.
Double-escaped text
If a page shows “&” or “<b>” literally, the text was escaped twice. Decode once and check where your system escapes – it should happen exactly one time, at output.