An HTML comment starts with <!-- and ends with -->.
Everything inside is ignored by the browser.
Why Use Comments?
In HTML, comments are notes or explanations you add inside your code that are not shown on the webpage. They’re useful for:
- Reminding yourself what a section of code does.
- Leaving notes for other developers working on the same project.
- Temporarily disabling code blocks for testing and debugging.
💬 **Syntax:** A comment begins with **<!--** and ends with **-->**.
Basic Comment Example:
<p>This is visible text.</p>
<!-- This is a comment and won’t appear on the page -->
<p>This is also visible text.</p>
<!-- This is a comment and won’t appear on the page -->
<p>This is also visible text.</p>
Multi-Lined Comment Example:
<!--
This is a multi-line comment.
You can write as much documentation as you need here.
-->
This is a multi-line comment.
You can write as much documentation as you need here.
-->
Disabling Code:
You can temporarily disable parts of your HTML by wrapping them in comments — a great way to test or debug layouts without deleting code.
<!--
<h1>This heading is hidden</h1>
<p>This paragraph is also commented out.</p>
-->
<h1>This heading is hidden</h1>
<p>This paragraph is also commented out.</p>
-->
Key Points & Warnings:
- Comments don’t affect how your page looks or behaves in the browser.
- They’re only visible by viewing the HTML source code.
- **Warning:** Do not use comments for sensitive information (like passwords or API keys). They are visible to anyone who views the page source.
- You can’t **nest** comments (put one comment inside another, i.e., <!-- ... <!-- ... --> ... -->).