HTML Β· Chapter 11 of 45
HTML Comments
HTML comments let you leave notes in your code that browsers ignore completely. They start with <!-- and end with -->.
Comments are useful for explaining sections of markup, temporarily disabling code while testing, or leaving TODO notes for teammates.
Syntax
<!-- comment text -->Syntax
Wrap any text in <!-- and --> to comment it out. Comments can span multiple lines and can even wrap entire blocks of HTML.
Common uses
Developers use comments to label sections (like <!-- Header --> or <!-- Footer -->) and to temporarily hide code without deleting it.
Example 1 (html)
<!-- This is a comment -->
<p>This text is visible.</p>Output
This text is visible.The comment does not appear in the rendered page.
Example 2 (html)
<!--
<p>This paragraph is hidden.</p>
-->
<p>This one shows.</p>Output
This one shows.Wrapping code in a multi-line comment disables it from rendering.
Key points
- Comments start with <!-- and end with -->.
- Browsers completely ignore comment content.
- Comments can span multiple lines.
- Useful for notes, labels, and temporarily disabling code.
π‘ Note: Remember comments are visible in page source β never put sensitive information inside them.
