HTML Basics

HTML Comments

Comments in HTML are notes or explanations added to your code for yourself or other developers.
They do not appear on the webpage, but are visible in the HTML source code. Comments make your code easier to understand and maintain.

What Is an HTML Comment?

An HTML comment is written using the following syntax:

Comment Example

html

<!-- This is a comment -->
  • Everything between <!-- and --> is ignored by the browser.
  • You can write single-line or multi-line comments.

Single-Line Comment Example

Single-line Comment

html

<p>This is a paragraph.</p>
<!-- This paragraph explains something important -->
  • The <p> text is visible on the webpage.
  • The comment is ignored and not displayed.

Multi-Line Comment Example

Multi-line Comment

html

<!--
This is a multi-line comment.
You can write explanations,
notes, or reminders here.
-->
<p>HTML comments are helpful for developers.</p>

Common Uses of HTML Comments

Code Documentation

Explain sections of code for yourself or other developers.

Debugging

Temporarily disable a part of your HTML code:

Example

html

<!-- <p>This paragraph is temporarily hidden.</p> -->

Organizing Code

Separate sections for better readability:

Organizing Example

html

<!-- Header Section -->
<header>...</header>

<!-- Navigation Section -->
<nav>...</nav>

Important Notes

  • Comments cannot be nested. Don’t put <!-- --> inside another comment.
  • Avoid overusing comments - only use them where necessary for clarity.
  • Comments are visible in the browser’s “View Page Source”, so don’t include sensitive information.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Conclusion

HTML comments are an essential tool for code documentation, organization, and debugging.
They help developers understand, maintain, and collaborate on projects without affecting what users see on the webpage.