Lesson 9 of 21 – HTML Comments
45%
45%

HTML Comments

HTML comments are not displayed in the browser, but they help document and explain your source code. Comments improve code readability and make maintenance easier.

Definition: HTML comments are placed between <!-- and -->.

Add Comments

Comments can be used to place reminders, explanations, or notes inside 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.
  • Use --> to end a comment.
  • Example: <!-- This is a comment -->

2. Ignored by Browser

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

3. Multi-line Comments

HTML comments can span across multiple lines.

Multi-line Comment Example
<!--
This is a multi-line comment.
It can span across several lines.
-->

4. Uses of Comments

  • Documentation: Explain code sections.
  • Debugging: Temporarily disable code.
  • Notes: Leave reminders for developers.

5. Do Not Nest Comments

HTML comments cannot be nested. Only the first --> ends the comment.

Benefits of Using Comments

  • Improves readability.
  • Makes teamwork easier.
  • Helps maintain large projects.
  • Useful for debugging.
Remember: Comments are ignored by the browser but are very important for developers.

🧠 Quiz

Which syntax is used for HTML comments?