HTML Comments

HTML comments allow developers to write notes inside the code without affecting the webpage's output. They help in understanding, debugging, and organizing the code.

How to Write a Comment in HTML?

<!-- This is a comment -->

Example:

        <p>This text will be visible.</p>
       <!-- <p>This text is inside a comment and will not appear on the webpage</p>-->
    

Types of HTML Comments

1️ Single-Line Comment

Used for short explanations or temporarily disabling a single line of code.

Syntax:

<!-- This is a single-line comment -->

Example:

        <!-- This is a heading -->
        <h1>Welcome to HTML</h1>
                             
        

2️ Multi-Line Comment

Used when writing longer notes or hiding multiple lines of code.

Syntax:

<!-- This is a multi-line comment.
It can span multiple lines. -->

Example:

        <!--
        <h1>This heading is hidden</h1>
        <p>This paragraph is also hidden.</p>
        -->
                             
        

Why Use HTML Comments?