agyanadda@gmail.com

HTML Comments

HTML Basics 1 min read Updated Nov 30, 2026 Topic 2 of 33

Comments are notes in your code that the browser does not show on the page.

Syntax

A comment starts with <!-- and ends with -->. Everything in between is ignored by the browser.

When to use comments

  • To explain a tricky part of the page for yourself or your team.
  • To mark where sections start and end in a long page.
  • To temporarily hide some HTML while testing, without deleting it.

Warning: Comments are hidden on the page but anyone can read them with "View Source". Never put passwords or private notes in comments.

Example

Example — Single and multi-line comments HTML
<!-- This is a single-line comment -->
<p>This paragraph is visible.</p>

<!--
  This is a comment
  over several lines.
-->

<!-- <p>This paragraph is hidden while testing.</p> -->
<p>Only two paragraphs appear on the page.</p>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which is the correct HTML comment?

Exercise 2 True / False

Visitors can read HTML comments by viewing the page source.

Frequently Asked Questions

Only very slightly, because they add bytes to the file. A few comments are fine; avoid huge commented-out blocks on live pages.