MakeW3web

Character Entities

Character entities, also known as HTML entities or character references, are used to represent special characters in HTML that cannot be easily typed or have a special meaning in HTML. Character entities are especially useful for displaying reserved characters (e.g., `<`, `>`,&`, and `"`), invisible or control characters, and characters that are not readily available on your keyboard.

Character entities are written using an ampersand (`&`), followed by a name or a number, and ended with a semicolon (`;`).

Here are some common character entities:

  1. `&lt;`: Less than sign (`<`)
  2. `&gt;`: Greater than sign (`>`)
  3. `&amp;`: Ampersand (`&`)
  4. `&quot;`: Quotation mark (`"`)
  5. `&apos;`: Apostrophe (`'`)
  6. `&nbsp;`: Non-breaking space (a space that prevents line breaks)
  7. `&copy;`: Copyright symbol (©)
  8. `&reg;`: Registered trademark symbol (®)
  9. `&trade;`: Trademark symbol (™)
  10. `&euro;`: Euro currency symbol (€)

In addition to the named character entities, you can also use numeric character references, which represent characters based on their Unicode code point. Numeric character references can be written in decimal or hexadecimal format.

Decimal format: `&#CODE;` (e.g., `&#169;` for the copyright symbol) Hexadecimal format: `&#xHEXCODE;` (e.g., `&#xA9;` for the copyright symbol)

To use character entities in your HTML code, simply include them where you want the special character to appear:

<p>The price of the product is 10 &euro;.</p>
<p>To display the "less than" symbol, use &lt; in your HTML code.</p>

Using character entities can help you ensure that your web pages display correctly across different browsers and platforms, even when special characters are involved.

Was this page helpful?