HTML Comments


HTML comments are placed in between <!-- ... --> tags. So, any content placed with-in <!-- ... --> tags will be treated as comment and will be completely ignored by the browser.

Single-line comments in HTML

Example

Let us see an example of single-line comments in HTML −

 Live Demo

<!DOCTYPE html>
<html>
<head> <!-- Document Header Starts -->
<title>This is document title</title>
</head> <!-- Document Header Ends -->
<body>
<p>Document content goes here.....</p>
</body>
</html>

Output

This will produce the following output. The text in the comments never gets printed −

Multi-line comments in HTML

Example

We can also set multi-line comments in HTML. Let us see an example −

 Live Demo

<!DOCTYPE html>
<html>
<head> <!-- Document Header Starts -->
<title>This is document title</title>
</head> <!-- Document Header Ends -->
<body>
<h2>Heading Two</h2>
<!--
This is a multiline comment and it can
span through as many as lines you like.
-->
<p>Document content goes here.....</p>
<p>We have set comments in the document as well, but it won't get displayed.</p>
</body>
</html>

Output

This will produce the following output. The text in the multi-line comment won’t get displayed −

Updated on: 17-Sep-2019

238 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements