Course Content
About Lesson

Definition:


HTML entities are special codes used to represent characters that have a special meaning in HTML or that cannot be easily typed directly from the keyboard. They are often used to display characters that would otherwise be interpreted as HTML markup, such as the less-than sign (“<“) or the ampersand (“&”). HTML entities are written using a specific syntax consisting of an ampersand followed by a code or name, and ending with a semicolon.

There are two main types of HTML entities:

  • Named Entities: These entities represent characters using their names. For example:
    • &lt; represents the less-than sign (“<“).
    • &amp; represents the ampersand (“&”).
    • &copy; represents the copyright symbol (“©”).
    • &nbsp; represents a non-breaking space (a space that prevents line breaks).
  • Numeric Entities: These entities represent characters using their Unicode or ASCII values. They are written as either decimal or hexadecimal numbers preceded by an ampersand and followed by a semicolon. For example:
    • &#60; represents the less-than sign (“<“).
    • &#38; represents the ampersand (“&”).
    • &#169; represents the copyright symbol (“©”).
    • &#160; represents a non-breaking space.

HTML entities are particularly useful when you need to include special characters in your HTML code, such as symbols, foreign characters, or characters that have special meaning in HTML, without causing parsing errors or unintended interpretation by the browser. They ensure that these characters are displayed correctly in the web browser.

Syntax:


< represents the less-than sign: <

Example:


HTML
<!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>

<p>In HTML, you can use entities to display special characters:</p>

<ul>
    <li>< represents the less-than sign: <</li>
    <li>> represents the greater-than sign: ></li>
    <li>& represents the ampersand: &</li>
    <li>© represents the copyright symbol: ©</li>
    <li>© also represents the copyright symbol using its numeric value: ©</li>
    <li>❤ represents the heart symbol using its hexadecimal value: ❤</li>
    <li>  represents a non-breaking space: Hello World</li>
</ul>

</body>
</html>

Output: