thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

01.04 · Introduction to HTML / Practice · 6 min

Commenting in HTML

Comments help you explain your code, set aside unused content and leave reminders for later.

Activity 4 of 4 in Introduction to HTML

All courses

HTML Basics / 01.04

Commenting in HTML

Not started

Use comments to temporarily hide HTML and leave a TODO for future work.

More options

Your lesson progress

Walkthrough: not startedPractice: not started

Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Rob illustrates use an HTML comment to explain the source without showing the note on the page.
Rob’s comic strip · Introduction to HTML

ORIGINAL WALKTHROUGH · 5:17

Watch with Rob.

Pause whenever you want to try a change. You can return to the lesson at any time.

LEARN WITH THE CODE ZONE

Unlock this video walkthrough

Written lessons and coding practice are free. Video walkthroughs are included with a paid Code Zone membership or an active free trial.

Have a Code Zone website account? Use your learning account’s email to get a six-digit sign-in code, or use your existing website password.

Need a website account? Paid Skool members and active trial members can use the email from their membership questions to request a sign-in code. No invite link or Skool password needed.

Close this window to keep practicing. After signing in, you’ll return to this lesson.

Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.

Open video & code editor (opens in a new tab)

Starter source code for VS Code

Copy the source below or download the file to follow along in VS Code.

The download includes a lesson link in each file and a README so you can find your way back.

index.html
index.htmlhtml · example
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Commenting HTML</title>
  </head>
  <body>
    <header>
      <img
        src="https://thecodezone.dev/favicon.svg"
        alt="Company Logo"
        width="64"
        height="64"
      />
    </header>

    <main>
      <h1>Introduction to HTML Comments</h1>

      <p>In this article, we will learn about the importance of HTML comments...</p>
    </main>
  </body>
</html>

Write a note the browser will not display

An HTML comment begins with <!-- and ends with -->. The browser keeps it in the source without displaying it as page content. Unlike JavaScript, HTML does not use // for comments.

The starter has no comments yet. Try adding <!-- Logo --> above the image as you follow the video. You can also explain why code exists or leave a reminder for future work. Anyone reading the page source can read your comments, so never put passwords or private information in them.

A comment explains the surrounding code
index.htmlhtml · example
<!-- Navigation links go here. -->
<nav>...</nav>

Set aside code without deleting it

Wrap a complete element in a comment to temporarily remove it from the preview. Keep the opening tag, text and closing tag inside the comment. You can restore it later by removing the comment markers.

In our editor, select a paragraph and press Command-/ on Mac or Control-/ on Windows to toggle its comment. On an empty HTML line, the same shortcut creates a comment with the caret ready for your note. Do not put one HTML comment inside another.

Only the second paragraph appears in the preview
index.htmlhtml · example
<!-- <p>Registration is closed.</p> -->
<p>New dates will be announced soon.</p>

Leave a TODO for your next change

Start a reminder with TODO: so it is easy to find when you return. A TODO is a note for a developer, not an instruction the browser executes.

In Your turn below, hide an expired promotion while keeping its source code. Then add a TODO immediately below the h1, before the next visible paragraph. The video workspace is ungraded so you can experiment freely.

A reminder directly below a heading
index.htmlhtml · example
<h1>Our next workshop</h1>
<!-- TODO: Add the workshop date. -->
<p>Details are coming soon.</p>

YOUR TURN

Hide an old promotion and leave a reminder

Open index.html and follow the checklist. Run the preview, then choose Check challenge. Keep the supplied content unless an item asks you to change it.

To pass this challenge
  • Inside the main element, find the complete paragraph containing Our old promotion has ended.
  • Surround that entire paragraph, including its tags, with an HTML comment. Preserve it in the source rather than deleting it.
  • Immediately after the closing tag of the h1 containing Community updates, add another HTML comment.
  • Make the reminder comment contain TODO: Add the next workshop date.
  • Keep the h1 and the paragraph Check back soon for our next workshop. visible. Neither the old promotion nor the TODO should appear in the preview.

Edit HTML, then run it to see the page. Check Challenge checks the rendered elements. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Need a nudge?

Hide the whole paragraph

Put <!-- before the paragraph’s opening <p> and --> after its closing </p>. Keep the paragraph’s text inside the comment.

Add a reminder below the heading

On the line after </h1>, type <!-- TODO: Add the next workshop date. -->. Do not put the reminder inside the h1 or inside the comment around the old promotion.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

HTML comments stay in the source but do not appear on the page. Use them for useful notes and temporary changes, never for secrets.