learn2kode.in

HTML Comments

Comments in HTML are used to add notes, explanations, or reminders inside the code.
They are not displayed in the browser — only visible in the page source.

Comments help developers understand, debug, and organize their HTML code easily.

Syntax

The basic syntax of an HTML comment is:

<!-- This is a comment -->

Everything inside <!-- and --> is treated as a comment by the browser.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Comments Example</title>
  </head>
  <body>
    <!-- Main heading of the page -->
    <h1>Welcome to Learn2Kode</h1>

    <!-- Paragraph about Learn2Kode -->
    <p>We help you learn web development step by step!</p>

    <!-- This comment will not be displayed in the browser -->
  </body>
</html>

Output

HTML Comments Example

Welcome to Learn2Kode

We help you learn web development step by step!

Multi-line Comments

You can write comments that span multiple lines — just keep the content inside the same <!-- --> block.

<!--
This is a multi-line comment.
You can use it to explain complex code
or temporarily disable a section.
-->

Commenting Out Code

Developers often use comments to disable (or “comment out”) code temporarily while testing.

Example

<!-- <p>This paragraph is temporarily hidden.</p> -->

Output

(Nothing is displayed because the code is commented out.)

Why Use Comments?