Advertisement
๐ŸŒ Beginner

HTML Entities โ€“ Special Characters in HTML

Some characters have special meaning in HTML โ€” like < (tag opening) and & (entity start). To display these characters as visible text you use HTML entities. Entities also let you insert special symbols (ยฉ, โ„ข, โ†’, non-breaking spaces) reliably across all browsers.

โฑ๏ธ 10 min read๐ŸŽฏ Beginner๐Ÿ“… Updated 2026

Why Entities Exist

The browser uses < and > to identify HTML tags, and & to start an entity. If you type these directly as content the browser gets confused:

HTML
<!-- Problem: browser thinks <script> is a real tag -->
<p>Use the <script> tag for JavaScript.</p>

<!-- Solution: escape the angle brackets -->
<p>Use the &lt;script&gt; tag for JavaScript.</p>
<!-- Renders as: Use the <script> tag for JavaScript. -->

Most Common HTML Entities

EntityCharacterDescription
&lt;<Less-than sign (tag open)
&gt;>Greater-than sign (tag close)
&amp;&Ampersand
&quot;"Double quote
&apos;'Apostrophe / single quote
&nbsp;(space)Non-breaking space โ€” prevents line break between words
&copy;ยฉCopyright symbol
&reg;ยฎRegistered trademark
&trade;โ„ขTrademark symbol
&mdash;โ€”Em dash
&ndash;โ€“En dash
&hellip;โ€ฆEllipsis
&euro;โ‚ฌEuro sign
&pound;ยฃPound sign
&rarr;โ†’Right arrow
&larr;โ†Left arrow
Advertisement

Practical Examples

HTML
<!-- Copyright footer -->
<p>&copy; 2026 ylearner. All rights reserved.</p>

<!-- Non-breaking space: prevents "10" and "km" splitting onto separate lines -->
<p>Distance: 10&nbsp;km</p>

<!-- Displaying code in text -->
<p>The &lt;div&gt; tag is a block container.</p>

<!-- Price range with en dash -->
<p>Price: &pound;10&ndash;&pound;50</p>

<!-- Trademark -->
<p>ylearner&trade; โ€” Learn to code for free.</p>

<!-- Numeric entity (decimal) -->
<p>&#169; 2026</p>  <!-- Same as &copy; -->

<!-- Numeric entity (hex) -->
<p>&#x2665;</p>  <!-- โ™ฅ -->

Entities vs Unicode in HTML5

With <meta charset="UTF-8"> (which every modern HTML5 page should have), you can type most special characters directly into your HTML file โ€” your code editor saves them as UTF-8 characters the browser reads correctly. Entities are still useful for <, >, and & which are structurally significant, and for non-breaking spaces.

HTML
<!-- In HTML5 with UTF-8, these are equivalent: -->
<p>&copy; 2026</p>
<p>ยฉ 2026</p>  <!-- Direct Unicode character -->

<!-- But these MUST use entities: -->
<p>&lt;tag&gt;</p>    <!-- Displaying < and > as text -->
<p>5 &amp; 10</p>   <!-- Displaying & as text -->

HTML Entities: Displaying Characters HTML Reserves

Some characters mean something to HTML itself โ€” a literal < starts a tag. To display them as text you use an entity: an escape code the browser renders as the real character.

CharacterEntityWhy escape it
<&lt;otherwise starts a tag
>&gt;closes a tag
&&amp;starts an entity
(space)&nbsp;non-breaking space
ยฉ&copy;not on the keyboard
<!-- To show: if (a < b && c > d) -->
<code>if (a &lt; b &amp;&amp; c &gt; d)</code>

The security angle: escaping <, >, and & in any user-supplied text is how you prevent XSS โ€” if a user types <script> and you render it raw, their script runs; escaped, it just shows as text. Templating engines auto-escape for this reason.

Two handy ones: &nbsp; is a space where the line must not break (e.g. "10&nbsp;kg"); overusing it for layout is a smell โ€” use CSS margins. Entities come in named (&copy;) and numeric (&#169;) forms; named are more readable.

๐Ÿ‹๏ธ Practical Exercise

  1. Display a literal less-than and greater-than sign using &lt; and &gt;.
  2. Show the copyright symbol in a footer using &copy;.
  3. Write 5 &lt; 10 and confirm the operator displays literally instead of being parsed.
  4. Add a non-breaking space between two words with &nbsp; so they never wrap apart.
  5. Display a price using the euro entity &euro; and the pound entity &pound;.

๐Ÿ”ฅ Challenge Exercise

Create a small "HTML cheat sheet" page that visibly shows the code for an anchor tag โ€” for example <a href="..."> โ€” as literal text on the page (not a working link). You will need entities for the angle brackets and quotes. Then add a copyright footer with the ยฉ symbol and the current year.

๐Ÿ“‹ Summary

  • HTML entities start with & and end with ; โ€” e.g. &amp;, &lt;, &copy;.
  • Must-escape: &lt; (<), &gt; (>), &amp; (&) โ€” these are structurally reserved in HTML.
  • &nbsp; โ€” non-breaking space, prevents unwanted line breaks.
  • In HTML5 with UTF-8, you can type most symbols directly. Entities are mainly needed for the reserved characters.

Interview Questions

  • What is an HTML entity and when do you need one?
  • How do you display a literal < character on a page?
  • Why must a literal ampersand be written as &amp;?
  • What does &nbsp; do and when is it useful?
  • What is the difference between a named entity and a numeric entity?

FAQ

Why does a bare & sometimes break my text? +

A lone & can be read as the start of an entity. Always write &amp; for a literal ampersand, especially inside text and URLs, to avoid parsing surprises.

Do I need entities for accented letters like รฉ? +

With UTF-8 encoding (the modern default) you can type accented characters directly. Entities are mainly required for the reserved characters <, >, and &.