Loading...

Using HTML Comments

HTML comments are notes not shown by the browser but are very useful during development. They help document the code, add explanations, or temporarily disable elements without deleting them.

Comment Syntax

A comment in HTML looks like this: <!-- This is a comment -->. It’s important that the comment is placed between <!-- and -->, otherwise it won’t be recognized.

What Are Comments Used For?

There are many reasons to use comments during development. For example, to explain why a specific piece of code is there, or what effect an element has. They can also help other developers who later work on the same code.

Practical Use of Comments

If you have a temporary header used for testing, you can easily comment it out: <!-- <h1>Test Header</h1> -->. This way, it won’t be deleted but also won’t appear. This is especially useful when working on a complex page where you don’t want to risk losing content.

Placing Comments in HTML

You can place HTML comments almost anywhere: in the <head>, at the beginning of the <body>, or directly before or after elements. Just make sure you don’t place comments inside HTML tag attributes – that’s not allowed.

Tips for Using Comments

  • Don’t over-comment, but always comment if something isn’t obvious.
  • Avoid redundant comments that just state what the code already makes clear.
  • Temporarily comment out HTML elements for testing instead of deleting them.
  • Use consistent formatting and language in comments, especially in team projects.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.


Top tools

CodeHubBoardly NEWLinksy NEWChromo NEW

Select Language

Set theme

© 2025 ReadyTools. All rights reserved.