How to create hidden comments in HTML?


Comments are used to hide content.

To create hidden comments in HTML, we add <! --- tag and end it with -- >. Whatever comes inside this tag it is hidden. These comments allow us to easily understand the code.

Comments can be considered as a note to yourself and allows the other person to understand the code, which also hides HTML code, so the browser doesn't display it on the web page.

Syntax

Following is the syntax to hide comments in HTML.

<!—The text to be commented -->

Example

Following is the example program to hide comments in HTML.

<!DOCTYPE html> <html> <body> <!-- The text here is a commented and it is hidden on the web page --> <p>DLF stands for Delhi Land and Finance</p> </body> </html>

Example

Following is another example program to hide comments in HTML.

<!DOCTYPE html> <html> <body> <!-- <ul> <li> 1 </li> <li> 2 </li> <li> 3 </li> </ul> --> <p>Delhi is the capital of India</p> </body> </html>

We use inline comment tag inside the <p> tag. To hide the content of the paragraph.

Example

Following is the example program to hide comments in HTML, using inline comment tag.

<!DOCTYPE html> <html> <body> <!-- The text here is a commente and it is hidden on the web page --> <p>DLF stands for Delhi Land and Finance<!--FinanceDelhi Land and Finance is one of the largest commercial real estate developer in India.--></p> </body> </html>

Updated on: 11-Nov-2022

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements