Tech 5 min read·By NexTool Team

HTML Character Entities Guide: Special Characters in HTML

Reference guide for HTML character entities. Learn how to display special characters, symbols, and Unicode in HTML using entity names and numeric codes.

ShareY

Try the free calculator

Use our JSON Formatter to run the numbers yourself.

Why HTML Entities Are Necessary

HTML uses certain characters as part of its syntax — angle brackets (< >) define tags, ampersands (&) begin entities, and quotes (") delimit attribute values. To display these characters as visible text rather than having the browser interpret them as code, you must use HTML entities. An entity starts with an ampersand and ends with a semicolon. The less-than symbol is &lt;, the greater-than is &gt;, the ampersand itself is &amp;, and the double quote is &quot;. Without entities, writing '<script>' in visible text would create an actual script tag, potentially enabling cross-site scripting (XSS) attacks. Entity encoding is a fundamental web security practice.

Named Entities vs. Numeric References

HTML supports three formats for entities. Named entities use memorable names: &copy; for the copyright symbol, &euro; for the euro sign, &mdash; for an em dash. Numeric decimal references use the Unicode code point: &#169; is also the copyright symbol (Unicode U+00A9 = 169 decimal). Numeric hexadecimal references prefix with x: &#x00A9; is the same copyright symbol. Named entities are easier to read in source code, but only about 250 named entities exist while numeric references can represent any of Unicode's 149,000+ characters. Use named entities for common symbols and numeric references for rare characters or when maximum compatibility is needed.

Common Entities Every Developer Should Know

Mandatory escapes: &lt; (<), &gt; (>), &amp; (&), &quot; ("), &#39; ('). Typographic: &mdash; (em dash), &ndash; (en dash), &hellip; (ellipsis), &laquo; and &raquo; (guillemets). Spaces: &nbsp; (non-breaking space), &ensp; (en space), &emsp; (em space), &thinsp; (thin space). Currency: &dollar; ($), &euro; (euro), &pound; (pound), &yen; (yen). Math: &times; (multiplication), &divide; (division), &plusmn; (plus-minus), &le; (less-or-equal), &ge; (greater-or-equal). Arrows: &larr; (left), &rarr; (right), &uarr; (up), &darr; (down). Miscellaneous: &copy; (copyright), &reg; (registered), &trade; (trademark), &deg; (degree), &para; (paragraph mark).

Recommended Resources

Sponsored · We may earn a commission at no cost to you

Modern Alternatives to HTML Entities

With UTF-8 encoding now standard across the web, many characters can be typed directly in HTML source code without entities. If your HTML document declares <meta charset="UTF-8">, you can type most symbols, accented characters, and even emoji directly. Entities are still required for the five reserved HTML characters (<, >, &, ", ') and are useful for non-breaking spaces (&nbsp;) and characters that might not render correctly in all text editors. In JavaScript, use textContent or innerText instead of innerHTML to automatically handle escaping. Template engines and frameworks like React automatically escape content by default, preventing XSS vulnerabilities.

Related Free Tools

Related Articles

Frequently Asked Questions

Do I still need HTML entities if I use UTF-8?

You must always escape the five reserved HTML characters: < > & " ' — these have structural meaning in HTML regardless of character encoding. For all other characters (symbols, accented letters, emoji), UTF-8 encoding allows direct use in your HTML source. Entities for non-reserved characters are optional but can improve source code readability and ensure compatibility with older systems.

What is the difference between &nbsp; and a regular space?

A non-breaking space (&nbsp;) prevents the browser from breaking a line between two words at that position, and multiple consecutive &nbsp; entities are each rendered (unlike regular spaces, which browsers collapse into one). Use &nbsp; between words that should stay together (like '100 km' or 'Dr. Smith') and for creating visible spacing. Regular spaces are collapsed by HTML — ten consecutive spaces display as one.

How do I display HTML code in a web page?

Replace < with &lt; and > with &gt; in all HTML tags you want to display as text. For example, to show '<div class="test">', write '&lt;div class=&quot;test&quot;&gt;'. Use the <code> element for inline code and <pre><code> for multi-line blocks. Most syntax highlighting libraries handle entity encoding automatically when you pass code as a text string.