HTML - Entities

In HTML, certain characters are reserved because they have special structural meaning in HTML markup. For instance, if you type the less-than sign (<) or greater-than sign (>) directly into plain text, the web browser interprets them as opening or closing HTML tags. To display reserved characters safely, or to render typographic symbols that do not exist on a standard keyboard (like ©, €, £, ™), HTML provides Character Entities.


1. HTML Character Entity Syntax

A character entity can be written in two standard formats:

  • Entity Name: Begins with an ampersand (&), followed by a mnemonic name, and ends with a semicolon (;). Example: &lt; displays <. (Easy to remember).
  • Entity Number (Decimal): Begins with an ampersand and hash (&#), followed by the decimal character code, and ends with a semicolon. Example: &#60; displays <. (Universally supported across all XML/HTML parsers).
  • Entity Number (Hexadecimal): Begins with &#x followed by the hex code. Example: &#x3C; displays <.

2. The Five Mandatory Reserved Characters

These five characters must always be replaced with character entities whenever used inside regular body text or attribute values:

Character Description Entity Name Entity Number (Dec) Entity Number (Hex)
< Less-than sign &lt; &#60; &#x3C;
> Greater-than sign &gt; &#62; &#x3E;
& Ampersand &amp; &#38; &#x26;
" Double quotation mark &quot; &#34; &#x22;
' Single quotation mark (apostrophe) &apos; &#39; &#x27;

3. The Non-Breaking Space (&nbsp;) Explained

In HTML, browsers automatically collapse consecutive whitespace characters (multiple spaces, tabs, and newlines) into a single space. If you want to force multiple consecutive spaces, you must use the non-breaking space entity: &nbsp;.

Crucial Word-Wrapping Function: A non-breaking space also prevents the browser from breaking a line between two linked terms. For example, writing 10&nbsp;MB or Section&nbsp;4 guarantees the number and its unit will never be split across two separate lines.


4. Frequently Used Typographic & Currency Entities

Symbol Description Entity Name Entity Number
© Copyright &copy; &#169;
® Registered Trademark &reg; &#174;
™ Trademark &trade; &#8482;
€ Euro Currency &euro; &#8364;
₹ Indian Rupee Symbol — &#8377;
£ British Pound &pound; &#163;
¥ Japanese Yen &yen; &#165;
¢ Cent &cent; &#162;
— Em Dash (Long Dash) &mdash; &#8212;
• Bullet Symbol &bull; &#8226;

5. Entity Encoding as a Cybersecurity Defense (XSS Prevention)

For bloggers and software engineers, understanding entity encoding is vital for security. If a user submits a malicious comment containing <script>stealCookies()</script>, storing and re-rendering that raw string in HTML executes the attacker's script (a Cross-Site Scripting / XSS vulnerability). By escaping and converting < into &lt; and > into &gt;, the browser safely prints the literal text without executing it.


6. Hands-on Practice Session: Professional E-Commerce Footer with Legal Entities

Assignment Scenario: Create a commercial website footer component incorporating copyright symbols, trade marks, non-breaking spaces for financial currency guarantees, and mathematical pricing calculations.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML Entities Practice</title>
  <style>
    .footer-box {
      background-color: #2c3e50;
      color: #ecf0f1;
      padding: 24px;
      font-family: Arial, sans-serif;
      border-radius: 6px;
      max-width: 650px;
      margin: 20px auto;
      line-height: 1.8;
    }
    .price-tag {
      color: #2ecc71;
      font-weight: bold;
    }
  </style>
</head>
<body>

  <div class="footer-box">
    <h3 style="margin-top: 0; color: #f1c40f;">Veewom Technologies&trade; Learning Portal</h3>
    <p>
      Annual Web Development Certification &bull; Special Student Offer: 
      <span class="price-tag">&#8377;&nbsp;1,999</span> 
      (Normally &euro;&nbsp;49 or &dollar;&nbsp;55).
    </p>
    <p>
      <em>Formula:</em> Passing Score &ge; 75% &amp;&nbsp;Lab Attendance &gt; 80%.
    </p>
    <hr style="border-color: #4a6278;">
    <p style="font-size: 13px; color: #bdc3c7; margin: 0;">
      &copy;&nbsp;2016&ndash;2026 Veewom.com&reg;. All Rights Reserved. 
      Unauthorized copying of tutorial materials is strictly prohibited by law.
    </p>
  </div>

</body>
</html>

7. BCA University Exam Viva Questions

An HTML character entity is a special code sequence used to display reserved characters (like <, >, and &) that the browser would otherwise interpret as HTML tags, or to display invisible characters (like non-breaking spaces) and symbols absent from a physical keyboard.
An entity name uses a descriptive word (e.g., &copy;), which is intuitive and easy to remember, but older browsers may lack definitions for rare symbols. An entity number references the character's exact Unicode decimal/hex code (e.g., &#169;), ensuring 100% universal rendering across all XML, SGML, and web browser parsers.
1. Preventing Whitespace Collapsing: It forces multiple consecutive horizontal spaces that browsers would otherwise collapse into one.
2. Preventing Line Wrapping: It glues two adjacent words or a number and its measurement unit together so they cannot be broken onto separate lines.
When user inputs are sanitized and escaped into character entities (e.g. converting <script> to &lt;script&gt;), the browser treats the characters strictly as printable strings rather than executable JavaScript instructions, defusing the attack.
The Indian Rupee symbol does not have a widely standardized named entity; it is rendered using the decimal entity code &#8377; or hexadecimal &#x20B9;.

8. Frequently Asked Questions (FAQ)

Omitting the trailing semicolon (e.g. writing &copy instead of &copy;) violates HTML syntax standards. While some modern browsers may guess the entity in simple contexts, XML parsers and strict validators will reject the document or display the raw characters.
Yes! With <meta charset="UTF-8">, you can directly paste symbols like ©, €, and ₹ directly into your HTML file. However, reserved characters (<, >, &, ") MUST still use character entities regardless of character encoding.
Escape the ampersand by writing &amp;lt;. The browser parses &amp; into a literal & and prints the remaining lt; as text.
Search engine crawlers understand character entities perfectly. Using proper entities for currency, registered trademarks, and dashes produces cleaner, professional SERP snippets and prevents search crawler parsing glitches caused by unescaped ampersands or angle brackets.
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!