Entities in html


Entities in HTML, also known as HTML character entities or HTML entities, are special codes that represent characters in HTML that are reserved or cannot be easily typed on a standard keyboard. They are used to ensure that certain characters are displayed correctly in the browser.


Syntax of HTML Entities

HTML entities start with an ampersand (&) and end with a semicolon (;). The entity name or number is placed between these two symbols.

There are two types of HTML entities:

  1. Named entities: These use a descriptive name.
  2. Numeric entities: These use a numeric code.


Common Named Entities

Reserved Characters

  • & - & (ampersand)
  • &lt; - < (less than)
  • &gt; - > (greater than)
  • &quot; - " (double quote)
  • &apos; - ' (single quote, apostrophe)


Special Characters

  • &nbsp; - Non-breaking space
  • &copy; - © (copyright)
  • &reg; - ® (registered trademark)
  • &trade; - ™ (trademark)
  • &euro; - € (euro)
  • &cent; - ¢ (cent)
  • &pound; - £ (pound)
  • &yen; - ¥ (yen)
  • &sect; - § (section sign)
  • &para; - ¶ (paragraph sign)
  • &bull; - • (bullet)
  • &hellip; - … (ellipsis)


Numeric Entities

Numeric entities can be written in decimal or hexadecimal form.

Decimal

  • &#34; - " (double quote)
  • &#38; - & (ampersand)
  • &#60; - < (less than)
  • &#62; - > (greater than)


Hexadecimal

  • &#x22; - " (double quote)
  • &#x26; - & (ampersand)
  • &#x3C; - < (less than)
  • &#x3E; - > (greater than)


Example Usage

<!DOCTYPE html>
<html>
<head>
    <title>HTML Entities Example</title>
</head>
<body>
    <p>Use &amp; to represent an ampersand (&amp;).</p>
    <p>Less than &lt; and greater than &gt; signs.</p>
    <p>Quotes: &quot;Double&quot; and &apos;Single&apos;.</p>
    <p>Non-breaking space: &nbsp; keeps text together.</p>
    <p>&copy; 2024 Company Name. All rights reserved.</p>
    <p>Price: 100&dollar;, 80&euro;, 70&pound;, 1000&yen;.</p>
</body>
</html>


In this example:

  • &amp; is used to display an ampersand.
  • &lt; and &gt; are used for the less than and greater than symbols.
  • &quot; and &apos; are used for double and single quotes.
  • &nbsp; is used for a non-breaking space.
  • &copy;, &dollar;, &euro;, &pound;, and &yen; are used for copyright, dollar, euro, pound, and yen symbols, respectively.


HTML entities ensure that your web content displays correctly and consistently across different browsers and platforms.