DevAcademy
LearnHTMLHTML Comments
BeginnerHTML

HTML Comments

Learn how to write comments in HTML to leave notes for yourself and other developers without affecting the rendered page.

Reading Time

6 min

Lesson

Lesson 6 of 27

Why Use Comments?

Comments let you leave notes inside your markup that are completely ignored by the browser. They are useful for explaining tricky sections, leaving reminders, or temporarily disabling a block of code.

Comment Syntax

<!-- This is a comment and will not be displayed -->
<p>This paragraph is visible.</p>

<!--
  Comments can also
  span multiple lines.
-->
Output

Commenting Out Code

Comments are handy for temporarily removing a section of markup while testing, without deleting it entirely.

Disabling a Section

<!--
<section class="promo">
  <h2>Limited Time Offer</h2>
</section>
-->
Output

Comments Are Not Truly Hidden

Anyone can view the page source and read your HTML comments. Never put sensitive information — like API keys or internal notes — inside them.

No Nested Comments

HTML comments cannot be nested. Placing <!-- --> inside another comment will close the outer comment early and can produce unexpected markup.

Best Practice

Use comments sparingly and only where the intent of a block of markup isn’t obvious. Well-structured, semantic HTML usually needs very few comments.

Interview Questions

Quick Quiz

1. What is the correct syntax for an HTML comment?

2. Are HTML comments visible in the page source?

3. Can HTML comments be nested inside each other?