HTML Entities: A Complete Guide to Encoding Special Characters
Published on June 4, 2026
If you have ever typed an ampersand in an HTML file and wondered why your page broke, or tried to display a copyright symbol only to see a garbled character instead, you have run head-first into the world of HTML entities. HTML entities are a fundamental part of web development that every developer, from beginners to seasoned professionals, needs to understand. They allow you to display characters that would otherwise be interpreted as HTML markup, and they ensure your content renders correctly across different browsers, operating systems, and character encodings. In this guide, we will cover what HTML entities are, when you need to use them, and provide a comprehensive reference to the most common codes.
What Are HTML Entities?
An HTML entity is a string of text that begins with an ampersand (&) and ends with a semicolon (;). It represents a specific character that the browser should render instead of interpreting as part of the HTML syntax. Entities come in two forms: named entities and numeric entities. Named entities use a descriptive name, such as & for an ampersand or © for a copyright symbol. Numeric entities use a decimal or hexadecimal number to reference a Unicode code point, such as © or © for the copyright symbol.
The primary purpose of HTML entities is to solve a fundamental problem: certain characters have special meaning in HTML. The less-than sign (<), for instance, tells the browser that a tag is beginning. If you want to display that character literally in your content, you cannot simply type it, because the browser will try to parse it as markup. By using the entity <, you tell the browser to render the symbol without treating it as code.
Another important use case is displaying characters that are not readily available on your keyboard or that may not be supported by the character encoding of your page. While modern web pages almost exclusively use UTF-8, which covers nearly every character you might need, HTML entities still serve as a reliable fallback and are often more readable in source code than raw Unicode characters. Seeing € in your HTML is instantly recognizable as the euro sign, whereas the raw Unicode character might be harder to spot in an editor that does not render it clearly.
Entities also play a role in accessibility and internationalization. Screen readers and assistive technologies handle named entities predictably, and using entities ensures that special characters are not lost or corrupted when content moves between systems with different encoding settings. For these reasons, understanding entities is not just about fixing broken pages, it is about writing robust, portable HTML.
When to Use HTML Entities
Knowing when to reach for an HTML entity is just as important as knowing which one to use. Here are the most common scenarios where entities are required or strongly recommended.
Displaying reserved HTML characters. The five characters that have special meaning in HTML markup must always be escaped when you intend to display them as text. These are the less-than sign (<), greater-than sign (>), ampersand (&), double quote ("), and single quote ('). Failing to escape these can cause broken layouts, invalid HTML, or even cross-site scripting vulnerabilities if user-generated content is involved. Every time you display code snippets, mathematical expressions, or any text that includes these characters, you should use the corresponding entity.
Publishing special symbols and punctuation. Copyright and trademark symbols, currency signs, mathematical operators, and arrows are common in content but may not render correctly across all systems if typed directly. Using named entities like ©, ™, £, or → ensures consistent display. This is especially important in email newsletters, RSS feeds, and other contexts where the rendering environment is unpredictable.
Handling non-breaking spaces. The entity inserts a space that prevents the browser from breaking the line at that point. This is useful for preventing orphaned words, keeping numbers and their units together (like "100 km"), or maintaining spacing in formatted text. Overusing non-breaking spaces can make your markup harder to maintain, but used sparingly they solve real layout problems without resorting to CSS tricks or wrapper elements.
International characters and accents. While UTF-8 handles characters like é, ñ, or ü natively, using named entities can make your source code more readable if your editing environment does not display those characters well. Additionally, if your page ever gets served with a non-UTF-8 encoding due to server configuration issues, entities will still render correctly whereas raw Unicode characters would appear as garbage.
Common HTML Entity Codes Reference Table
The following table lists the most frequently used HTML entities. You can refer to this whenever you need to encode a special character in your web projects.
| Character | Named Entity | Numeric Entity | Description |
|---|---|---|---|
| < | < |
< |
Less-than sign |
| > | > |
> |
Greater-than sign |
| & | & |
& |
Ampersand |
| " | " |
" |
Double quotation mark |
| ' | ' |
' |
Single quotation mark |
| © | © |
© |
Copyright symbol |
| ® | ® |
® |
Registered trademark |
| ™ | ™ |
™ |
Trademark symbol |
| € | € |
€ |
Euro currency sign |
| £ | £ |
£ |
Pound sterling |
| ¥ | ¥ |
¥ |
Japanese yen |
|
  |
Non-breaking space | |
| — | — |
— |
Em dash |
| … | … |
… |
Horizontal ellipsis |
| ← | ← |
← |
Left arrow |
| → | → |
→ |
Right arrow |
HTML Entities vs URL Encoding
A common source of confusion among new developers is the difference between HTML entities and URL encoding (also called percent-encoding). While both techniques involve replacing special characters with standardized sequences, they serve entirely different purposes and operate in different contexts.
HTML entities are used exclusively within HTML documents. They are processed by the browser's HTML parser before the content is rendered on the page. If you write & in your HTML, the browser displays an ampersand. URL encoding, on the other hand, is used within URLs to represent characters that are not allowed in a URI, such as spaces, non-ASCII characters, or characters that have special meaning in a URL (like ?, #, and &). In a URL, a space becomes %20, and an ampersand becomes %26.
The two systems use different syntax and are not interchangeable. Putting a URL-encoded sequence like %20 directly into your HTML will not produce a space, it will render the literal text "%20". Conversely, using in a URL will not insert a space, it will likely break the URL. When you are building a URL that contains query parameters, you use URL encoding. When you are writing content inside an HTML document, you use HTML entities. Tools like the ToolBox HTML Entity Encoder handle the former, while a URL encoder handles the latter. Understanding the distinction will save you from debugging sessions where your links do not work or your special characters fail to render.
Best Practices for Web Developers
Using HTML entities effectively is about more than memorizing codes. Adopting the right habits will keep your markup clean, your content reliable, and your maintenance workload low.
Always escape user-generated content. If your site accepts comments, reviews, or any form of user input that gets displayed on the page, you must escape HTML special characters before output. Failing to do so is one of the most common causes of cross-site scripting (XSS) vulnerabilities. Server-side template engines like Twig, Jinja2, and React's JSX automatically escape output by default, but if you are generating HTML strings manually, be sure to convert <, >, &, and " every time.
Use named entities for readability. While numeric entities work perfectly well, named entities like © are far easier to read and remember than ©. Most modern code editors will display named entities in a way that makes them stand out, so you can quickly scan your markup for encoded characters. Reserve numeric entities for characters that do not have a common named equivalent.
Do not overuse non-breaking spaces. The entity is a powerful tool, but it is often misused as a quick fix for layout problems. Instead of sprinkling non-breaking spaces throughout your content to force spacing, use CSS properties like margin, padding, and white-space. Overusing makes your HTML harder to read and maintain.
Use a tool when dealing with bulk conversions. If you have a large block of text that contains numerous special characters, manually replacing each one is tedious and error-prone. A dedicated HTML Entity Encoder can process your entire text at once, converting every special character to its proper entity. This is especially useful when migrating content from a word processor or when preparing documentation that includes code samples.
Validate your HTML. After adding entities to your markup, run your page through the W3C HTML validator. Invalid entities (like a typo where you wrote &copry; instead of ©) will be flagged as errors. Validation gives you confidence that your entities will render correctly across all browsers.
Frequently Asked Questions
Do I need to encode every special character in HTML?
No. Most characters, including letters, digits, and standard punctuation, can be used as-is. You only need to encode characters that have special meaning in HTML (like <, >, and &) or characters that might not render correctly due to encoding issues. In practice, you should always encode the five reserved characters in user-generated content and use named entities for symbols as needed for readability.
What is the difference between and a regular space?
A regular space allows the browser to break the line at that point if needed. A non-breaking space ( ) prevents line breaks. This is useful for keeping elements like "Mr. Smith" together on the same line or preventing a lone word from wrapping to a new line. Visually, they appear identical, but they behave differently during text flow.
Are HTML entities case-sensitive?
Yes, HTML entity names are case-sensitive. © produces a copyright symbol, but © will not work. Numeric entities are not case-sensitive, so © and © are both valid. Always check the casing when using named entities, especially for less common ones.
Can I use HTML entities in JSON or JavaScript?
No. HTML entities are only processed within HTML documents. If you include © inside a JSON file or a JavaScript string, it will be treated as literal text. In JavaScript, you can use Unicode escape sequences like © or simply include the character directly if your file uses UTF-8 encoding.
HTML entities may seem like a small detail in the grand landscape of web development, but they are one of those foundational concepts that every developer encounters constantly. Whether you are building a blog, an e-commerce platform, or a documentation site, knowing how to properly encode special characters ensures your content displays correctly, your site remains secure, and your code is maintainable. Bookmark a reliable HTML Entity Encoder and refer to the reference table above whenever you need to look up a code quickly.
Try Our Free Tools
These complementary tools will help you work with text encoding and data transformation in your daily workflow.
- HTML Entity Encoder - Instantly encode or decode HTML entities in any text.
- JSON Formatter - Format, validate, and beautify your JSON data.
- Base64 Encoder - Encode text or data to Base64 format for secure transmission.
- URL Encoder - Encode and decode URLs with proper percent-encoding.