LESSON 13

HTML Comments

Learning objective: Leave notes in your code that the browser ignores.

Understand

Comments help you and others understand your HTML.

An HTML comment is written between <!-- and -->. The browser ignores it, so it is perfect for notes, reminders, or temporarily disabling a chunk of markup while you experiment.

Analogy: A comment is like a sticky note in the margin: helpful to read, but not part of the final page.

See It in Action

A comment and some code:

<!-- Main navigation goes here -->
<nav>...</nav>
<!-- <p>Hidden for now</p> -->
How it works: The first comment is a note; the second wraps a paragraph so it is temporarily disabled without being deleted.

Try It Yourself

  1. Add a comment above a section explaining what it does.
  2. Comment out one element and refresh to see it disappear.
  3. Un-comment it to bring it back.

Quick Quiz

How does the browser treat an HTML comment?

Challenge

Add helpful comments to label the main parts of one of your pages.

Success condition: Your page has clear comments and none of them appear on screen.