HTML Comments

HTML comments are used to add notes inside the code that are not displayed in the browser.
They help developers understand, organize, and manage HTML code.


HTML Comment Syntax

<!-- This is an HTML comment -->
  • Comments start with <!--
  • Comments end with -->
  • Anything inside is ignored by the browser

Single-Line Comment Example

<!-- Main heading of the page -->
<h1>HTML Comments</h1>

The comment will not appear on the web page.


Multi-Line Comment Example

<!--
This section contains
introductory content
for the HTML tutorial
-->
<p>Welcome to HTML.</p>

Useful for explaining sections of code.


Commenting Out HTML Code

Comments are often used to temporarily disable code.

<!--
<p>This paragraph is disabled and will not appear.</p>
-->

The browser ignores the commented code.


Comments Inside Elements

<p>
  HTML is easy
  <!-- this is a note for developers -->
  to learn.
</p>

The comment does not affect text display.


Important Notes

  • Comments are visible in page source, not on the page
  • Do not put sensitive information in comments
  • Avoid excessive comments in production code
  • Comments cannot be nested

Why HTML Comments Are Useful

  • Improve code readability
  • Help during debugging
  • Make collaboration easier
  • Allow temporary code removal