HTML Entities

Introduction

HTML entities are used to display reserved characters in HTML, ensuring they are rendered correctly by the browser. These entities are also used to display characters that do not appear on the keyboard. HTML entities start with an ampersand (&) and end with a semicolon (;).

Common HTML Entities

Reserved Characters

Reserved characters in HTML must be replaced with character entities to be displayed correctly.

  • & (Ampersand): &
  • < (Less Than): &lt;
  • > (Greater Than): &gt;
  • " (Double Quote): &quot;
  • ' (Single Quote or Apostrophe): &apos; (or &#39;)

Example

<p>This &amp; that</p>
<p>10 &lt; 20</p>
<p>10 &gt; 5</p>
<p>He said, &quot;Hello!&quot;</p>
<p>It&apos;s a nice day</p>

Non-Breaking Space

A non-breaking space (&nbsp;) prevents the browser from collapsing multiple spaces into a single space and prevents line breaks at its location.

Example

<p>First&nbsp;Second&nbsp;Third</p>

Mathematical Symbols

HTML entities can also represent mathematical symbols.

  • + (Plus): &plus;
  • - (Minus): &minus;
  • × (Multiplication): &times;
  • ÷ (Division): &divide;

Example

<p>5 &plus; 5 = 10</p>
<p>10 &minus; 5 = 5</p>
<p>5 &times; 5 = 25</p>
<p>10 &divide; 2 = 5</p>

Greek Letters

HTML entities are used to display Greek letters.

  • Α (Alpha): &Alpha;
  • Β (Beta): &Beta;
  • Γ (Gamma): &Gamma;
  • Δ (Delta): &Delta;

Example

<p>&Alpha; &Beta; &Gamma; &Delta;</p>

Currency Symbols

HTML entities represent various currency symbols.

  • $ (Dollar): &dollar;
  • (Euro): &euro;
  • £ (Pound): &pound;
  • ¥ (Yen): &yen;

Example

<p>&dollar;100</p>
<p>&euro;100</p>
<p>&pound;100</p>
<p>&yen;100</p>

Other Special Characters

HTML entities represent various other special characters.

  • © (Copyright): &copy;
  • ® (Registered): &reg;
  • (Trademark): &trade;
  • ° (Degree): &deg;

Example

<p>&copy; 2023 Company Name</p>
<p>Trademark: &trade;</p>
<p>Temperature: 25&deg;C</p>

Complete List of Common HTML Entities

Character Entity Name Entity Number
& &amp; &#38;
< &lt; &#60;
> &gt; &#62;
" &quot; &#34;
' &apos; &#39;
© &copy; &#169;
® &reg; &#174;
&trade; &#8482;
° &deg; &#176;
± &plusmn; &#177;
× &times; &#215;
÷ &divide; &#247;
&para; &#182;
§ &sect; &#167;
&bull; &#8226;
&ndash; &#8211;
&mdash; &#8212;
&prime; &#8242;
&Prime; &#8243;
&permil; &#8240;
&Dagger; &#8225;
&lsaquo; &#8249;
&rsaquo; &#8250;
&Dagger; &#8225;

Example: Using Multiple HTML Entities in a Document

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Entities Example</title>
</head>
<body>
    <h1>HTML Entities Examples</h1>
    <section>
        <h2>Reserved Characters</h2>
        <p>This &amp; that</p>
        <p>10 &lt; 20</p>
        <p>10 &gt; 5</p>
        <p>He said, &quot;Hello!&quot;</p>
        <p>It&apos;s a nice day</p>
    </section>

    <section>
        <h2>Non-Breaking Space</h2>
        <p>First&nbsp;Second&nbsp;Third</p>
    </section>

    <section>
        <h2>Mathematical Symbols</h2>
        <p>5 &plus; 5 = 10</p>
        <p>10 &minus; 5 = 5</p>
        <p>5 &times; 5 = 25</p>
        <p>10 &divide; 2 = 5</p>
    </section>

    <section>
        <h2>Greek Letters</h2>
        <p>&Alpha; &Beta; &Gamma; &Delta;</p>
    </section>

    <section>
        <h2>Currency Symbols</h2>
        <p>&dollar;100</p>
        <p>&euro;100</p>
        <p>&pound;100</p>
        <p>&yen;100</p>
    </section>

    <section>
        <h2>Other Special Characters</h2>
        <p>&copy; 2023 Company Name</p>
        <p>Trademark: &trade;</p>
        <p>Temperature: 25&deg;C</p>
    </section>
</body>
</html>

Conclusion

HTML entities are essential for displaying reserved and special characters correctly on web pages. By using entities like &amp;, &lt;, &gt;, &quot;, &apos;, and many others, you can ensure that your web content is rendered accurately. Understanding and using HTML entities is crucial for creating well-structured and readable web pages.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top