iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML Entities

HTML entities are codes that represent characters which would otherwise be interpreted as markup — like < or & — or which can't be typed easily.

Most-used entities

EntityRenders asUse for
&lt;<Less-than sign — when writing about HTML tags.
&gt;>Greater-than sign.
&amp;&Ampersand — escape inside attribute values too.
&quot;"Double quote inside an attribute.
&apos;'Single quote inside an attribute.
&nbsp;(non-breaking space)Glue two words so the browser doesn't break the line between them.
&copy;©Copyright symbol.
&reg;®Registered trademark.
&mdash;Em dash.
&hellip;Ellipsis.

Numeric entities

Any Unicode character can be written as a numeric entity:

  • Decimal: &#9731; renders ☃ (snowman).
  • Hex: &#x2603; renders ☃ (same snowman).
Tip: If the page is UTF-8 (it should be), you can paste most special characters directly into the source instead of escaping them.

Example

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML Entities</title>
</head>
<body>

<h1>HTML Entities</h1>
<p>This is a demo page for the "HTML Entities" lesson.</p>

</body>
</html>
Try it Yourself »

Exercise

Write the entity for the less-than sign so it renders as text.

<p>If a b then…</p>

Test yourself

Q1. Display a literal "<" character with…
Q2. Display an ampersand with…
Q3. Non-breaking space is…

Discussion

Loading…