Home Videos Exercises MCQ Q&A Quiz E-Store Services Blog Sign in Appointment Payment

HTML Comments

HTML comments are not displayed in the browser, but they can help document your HTML source code.

Comments of any code make code easy to understand and increase readability of code.

Comments are also part of the code, which gives an explanation of the code.

In HTML, comments are used to add notes or explanations in the code without displaying them on the webpage. HTML comments are placed between <!-- and -->.


Add Comments

With comments you can place notifications and reminders in your HTML code:

Example:
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Remember to add more information here -->


Key Points for HTML Comments:


1. Syntax:

  • Use <!-- to start a comment and --> to end it.
  • Example: <!-- This is a comment -->

2. Ignored by the Browser:

  • Comments do not appear on the webpage and are only visible in the HTML source code.

3. Multi-line Comments:

  • You can use comments across multiple lines.
  • Example:
    <!-- This is a multi-line comment.
    It can span across several lines.-->


4. Uses

  • Documentation: Explaining parts of the code.
  • Debugging: Temporarily disabling code by commenting it out.
  • Notes: Adding reminders or explanations for yourself or other developers.

4. Do not nest comments:

  • HTML comments cannot be nested. If you attempt to nest them, only the first --> will end the comment, leading to issues in the code.