HTML Comments

HTML Comments are not displayed in the browser, which can help us in documenting our HTML source code.

Comments can be used for many purposes and here are some of them.

  • Source code documentation, which is very important for a developer
  • Reminders for future changes or enhancements
  • Hide content temporarily while development testing

The syntax looks as below, which can be a block or inline comment.

<!-- Comment content goes here -->

Comment can extend to multiple lines as below.

<!-- 
Comments line 1
Comments line 2
Comments line 3 
-->

Example

We can check the outcome of the below HTML document to see how it looks.

<!doctype html>
<html lang="en">
<head>
</head>
<body>
    <h1>HTML Comments</h1>

    <!-- Single line comment -->

    <!-- Multiple lines comment
        It can extent to multiple lines as shown here.
    -->

    <p>This paragraph <!-- Inline comment -->  has an inline comment.</p>
</body>
</html>

Overall

Make it a habit of writing useful comments, which is very important for source code documentation.