Comments are notes you leave in your code for yourself and other developers. They do not show up on the webpage โ only people who look at your HTML source code will see them.
Every developer, from beginners to professionals, uses comments. They are one of those habits that separates messy code from maintainable code.
Writing Comments
In HTML, a comment starts with <!-- and ends with -->. Everything between those markers is invisible to the user.
<!-- This is a comment. Nobody will see this on the page. -->
<p>This paragraph is visible.</p>
<!-- Another comment here. You can write anything you want. -->
Try it Yourself โ
Why Comments Help
Let me give you a few real scenarios where comments save the day:
- Explaining complex sections โ When you write a tricky piece of HTML, leave a comment explaining what it does. Future you will thank past you.
- Dividing sections โ In a long HTML file, comments act as signposts. You can write
<!-- Header Section -->and<!-- Footer Section -->to navigate quickly. - Temporarily hiding code โ If you want to remove something without deleting it forever, wrap it in a comment. This is called "commenting out" code.
<!-- Header - loads navigation and branding -->
<header>
<h1>My Website</h1>
<nav>...</nav>
</header>
<!-- <p>This paragraph is temporarily hidden.</p> -->
<!-- Footer - copyright and links -->
<footer>
<p>© 2026 My Website</p>
</footer>
Commenting Best Practices
Do not overdo it. Comments should explain why, not what. If your code is clean and well-structured, the "what" is usually obvious. Use comments when the intent behind the code is not immediately clear.
Also, remember that comments are visible in the page source. Anyone can view your HTML source and read your comments. Do not put sensitive information like passwords, API keys, or personal notes in comments.