Geek Slack

Introduction to HTML



    HTML Entities


    HTML Entities

    HTML entities are used to represent characters that have special meanings in HTML or characters that cannot be easily typed using a standard keyboard. These entities ensure that the characters are displayed correctly in a web browser.

    1. Basic HTML Entities

    Some characters, such as the less-than (<) and greater-than (>) symbols, must be represented by entities because they are used in HTML tags.

    Example:

    To display the less-than symbol, use &lt;:

    <p>5 &lt; 10</p>

    This will display as:

    5 < 10

    2. Non-breaking Space

    A non-breaking space is used to create a space that will not break into a new line.

    Example:

    To create a non-breaking space, use &nbsp;:

    <p>This is a non-breaking space.</p>

    This will display as:

    This is a non-breaking space.

    3. Reserved Characters

    Some characters are reserved in HTML and must be replaced with character entities to be displayed correctly.

    Example:

    Reserved characters include:

    • &lt; – less than
    • &gt; – greater than
    • &amp; – ampersand
    • &quot; – double quote
    • &apos; – single quote

    Example usage in HTML:

    <p>Tom &amp; Jerry</p>

    This will display as:

    Tom & Jerry

    4. Symbols

    HTML entities can be used to display various symbols, such as mathematical operators, currency symbols, and more.

    Example:

    Some commonly used symbols include:

    • &copy; – ©
    • &reg; – ®
    • &euro; – €
    • &cent; – ¢
    • &pound; – £

    Example usage in HTML:

    <p>&copy; 2024 Your Company</p>

    This will display as:

    © 2024 Your Company

    5. ASCII Characters

    HTML entities can be used to display ASCII characters by using their decimal or hexadecimal code values.

    Example:

    Displaying the letter “A” using its ASCII value:

    <p>A</p>  
    <p>A</p>  

    Both examples will display as:

    A

    6. Combining HTML Entities

    You can combine multiple HTML entities to display a sequence of special characters.

    Example:

    Combining entities to display a mathematical expression:

    <p>5 &lt; 10 &amp; 10 &gt; 5</p>

    This will display as:

    5 < 10 & 10 > 5

    Conclusion

    Using HTML entities is essential for displaying special characters and symbols correctly in a web page. Understanding and using these entities ensures that your HTML content is accurately represented and easily readable by users and browsers.