HTML comments, online

Six activities your students do on their own devices. See who's finished, and their scores.

HTML comments in one minute

What students need to know

Every HTML comment must begin with <!-- and end with -->. Anything in between is the comment text. The comment appears in the HTML file and can be read by anyone who views the source, but it is never rendered on the page.

Content inside <!-- --> is ignored by the browser and never shown to the user. // is used for comments in JavaScript, not HTML. HTML comments always use <!-- and -->.

Mistakes students make

  • The comment opening marker must be <!-- with no spaces between < and !--. Writing <! -- is invalid syntax.
  • The opening comment marker must be <!-- with two hyphens. Writing <!- with only one hyphen is invalid syntax.
  • The comment closing marker must be --> with two hyphens. Writing -> with only one hyphen leaves the comment unclosed.
  • // is not valid HTML comment syntax. HTML comments must use <!-- to open and --> to close, not the // style used in JavaScript.

Discover other journeys with this module

What students will learn in this module

Every question in Module 7

Quick questions

  1. Which of these correctly opens an HTML comment?A<!--B<!-
  2. True or false: HTML comment text is displayed on the page.AFalseBTrue
  3. Which of these correctly closes an HTML comment?A->B-->
  4. True or false: // is valid HTML comment syntax.AFalseBTrue
  5. Can an HTML comment span multiple lines?ANoBYes

Key terms

Students type the meaning of:

  • <!-- -->

Match the pairs

<!-- This is a comment -->Match it to what it does
<!-- <p>Old text</p> -->Match it to what it does
An HTML comment opens with <!-- and closes with -->Match it to what it does
Comments are visible in the page source but not in the browser windowMatch it to what it does
<!- This is a comment -->Match it to what it does
<!-- unclosed comment
<p>Text</p>
Match it to what it does

Fill in the blanks

  1. <body>
      ___ This is a comment -->
    </body>

    Hint: Type the characters that open an HTML comment

  2. <body>
      <!-- This is a comment ___
    </body>

    Hint: Type the characters that close an HTML comment

  3. <body>
      <!-- Navigation ___
      <h1>Home</h1>
    </body>

    Hint: Type the closing marker that ends an HTML comment

  4. <body>
      ___ <p>Draft text</p> -->
      <p>Live text</p>
    </body>

    Hint: Type the opening marker that starts an HTML comment

  5. <body>
      <!-- TODO: add image ___
      <p>Content</p>
    </body>

    Hint: Type the two hyphens and angle bracket that close a comment

Spot the error

Question 1

A<! -- This is a comment -->B  <h1>Title</h1>C  <p>Text</p>

Question 2

A<body>B  <!- This is a comment -->C  <p>Content</p>D</body>

Question 3

A<body>B  <h1>Heading</h1>C  <!-- Note: update this ->D  <p>Text</p>

Question 4

A<body>B  <h1>Title</h1>C  <p>Hello</p>D  // This is a note

Question 5

A<body>B  <!-- start -->C  <p>Text</p>D  <!-- <!-- nested --> -->E</body>