Comments, Entities & Symbols
Some characters have a special job in HTML, so you can't always type them directly. Character entities let you display them safely, along with symbols that aren't on your keyboard. Comments let you leave notes in your code that the browser doesn't display.
Comments
A comment starts with <!-- and ends with -->. Everything between is ignored by the browser and not shown on the page.
<!-- Main navigation starts here --> <nav>…</nav> <!-- TODO: add the events section after the committee meeting. Ask Otieno for the photos. -->
Use comments to explain sections of a long page, to leave reminders, and to "switch off" code temporarily while testing:
<!-- <p>Registration closes on Friday.</p> -->
Comments are hidden on the page but not secret. Anyone can read them with View Source (Ctrl+U). Never put passwords, API keys, private phone numbers or rude remarks about clients in HTML comments.
Two more rules: comments cannot be nested (the first --> ends the comment, even if you opened two), and the text inside should not contain --> for the same reason.
Why entities exist
The browser treats < as the start of a tag. Suppose you want to show a maths fact:
<p>We know that 5 <b and b > 2.</p>
The browser sees <b as the start of a bold tag, so part of your sentence can vanish or turn bold. The fix is to write the character as an entity: an ampersand, a name, and a semicolon. < displays as <.
<p>We know that 5 < b and b > 2.</p>
Now the browser displays exactly: 5 < b and b > 2.
Common entities
| You write | Browser shows | Meaning |
|---|---|---|
< | < | Less-than sign |
> | > | Greater-than sign |
& | & | Ampersand |
" | " | Double quote (useful inside attribute values) |
' | ' | Apostrophe |
| (a space) | Non-breaking space |
© | © | Copyright |
€ | € | Euro sign |
— | — | Em dash |
The ampersand itself must be escaped when it could be mistaken for the start of an entity. Writing & for every literal ampersand, as in Tom & Jerry, is the safe habit.
The non-breaking space
is a space that never breaks across lines. Use it to keep things together that would look wrong if split, such as an amount and its currency: KES 500 or 10 km. Don't use rows of to indent or space out content; that's CSS's job.
Numeric references
Every character has a number in Unicode, the worldwide character standard. You can write any character with &# and its decimal number, or &#x and its hexadecimal number:
<p>© 2026 Nyota Youth SACCO</p> <p>✓ Registration complete</p>
The first line shows "© 2026 Nyota Youth SACCO" (169 is the copyright sign) and the second shows a tick: "✓ Registration complete" (hex 2713 is the check mark).
Do you need entities for symbols?
Not usually. Because your page uses <meta charset="utf-8">, you can type symbols such as ©, €, é, ✓ and emoji directly into your HTML, and they will display correctly. Today you mainly need entities for:
<and&in text (and>for consistency),"inside a double-quoted attribute value,- invisible characters such as
, which are hard to see in your editor.
When you show HTML code on a web page, as this tutorial does, every < in the example must be written as <. Otherwise the browser runs your example instead of displaying it.
Try it
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Entities</title>
</head>
<body>
<!-- This comment never appears on the page -->
<h1>Entities & comments</h1>
<p>To start a paragraph, type <p>.</p>
<p>Ticket price: KES 1,500</p>
<p>Done ✓ and typed directly: ✓</p>
<p>© 2026 Kuza Ndoto Club — all rights reserved.</p>
</body>
</html>
The preview shows the heading "Entities & comments", the sentence "To start a paragraph, type <p>." with the tag visible as text, the price kept on one line, two ticks, and a copyright line with an em dash. The comment is not shown. Try replacing <p> with a real <p> and see what happens.
Key points
- Comments (
<!-- … -->) are hidden on the page but visible in the source, so keep them free of secrets. - Write
<as<,>as>and&as&when you mean them as text. keeps words together on one line; numeric references such as©can produce any Unicode character.- With UTF-8, most symbols can be typed directly.
Tip: use the ← and → keys to move between pages.
