HTML ยท Module 01 ยท Lesson 4 of 54

HTML Code Comments

What are HTML Comments?

Imagine writing sticky notes on the back of a canvas painting. The visitors in the gallery can't see the sticky notes, but other artists or curators can read them to understand how the painting was set up. In HTML, Comments are notes written in the code that are completely ignored by the browser when rendering the page.

Why does it matter?

As your code grows, it becomes harder to keep track of what different sections do. Comments help you:
  • Leave notes for yourself or other developers explaining why you built something a certain way.
  • Temporarily disable parts of your code to test things without deleting them.
  • How to write it

    An HTML comment starts with <!-- and ends with -->. Anything you put between these two markers will be invisible on the live website.

    Here is the comment syntax:

    <!-- This is a comment and won't show up on the website -->
    <p>This paragraph is visible to visitors!</p>
    

    <!-- Comment is invisible -->
    <p>Paragraph is visible</p>

    Common Mistakes

  • Forgetting to close the comment: If you write <!-- but forget the closing -->, the browser will think the rest of your entire webpage is a comment and hide everything!
  • Nesting comments: You cannot place a comment inside another comment (e.g., <!-- text <!-- nested --> text -->). This will break the rendering.
  • Quick Reference

  • <!-- comment text --> โ€” Invisible developer note.
  • Your Task
    Create a comment containing the text 'This is a test comment' below the paragraph.
    index.html
    Type code above to start the lesson.
    Live Preview