DEV Community

Cover image for HTML comment tag
johar ali
johar ali

Posted on

HTML comment tag

In HTML, you can use the <!-- and --> tags to create comments within your HTML code. Comments are not displayed on the web page and are intended for developers to include notes, explanations, or other information within the HTML source code.

HTML Comments are used to make our code more readable. Comments are completely hidden on the webpage, but you can see them in the code. Commenting code is generally considered a good practice, it helps us express what the code is doing, and serves as an anchor for you if you want to change something in your code in the future. Can act as. In a collaborative environment, code comments are helpful to other developers as well.

You can divide it into three parts.

Opening

Here, less than mark (<), Exclamation Mark (!) and two Dash (–) have to be written in the opening.

Closing

In closing you have to write two dashes (–) and greater than mark (>).

Comment Text

What you write between opening and closing is called comment text. And this comment text is not visible to the web page.

Types of Comment

Single-line Comments
Multi-line Comments
Conditional Comments

Single-line Comments
When you write comments in one line in HTML Documents, we call it Single Line Comments.

<!DOCTYPE html>
<html>
<body>
<!-- This Is Single Line Comment -->
<p>Comment line in HTML</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Here your browser does not show the comment in the output. Comment only helps in understanding coding.

Multi-line Comments

When you write comments in more than one line in HTML Documents, we call it Multi Line Comments.

<!DOCTYPE html>
<html>
<body>
<!-- This
Is
Multi Line Comment -->
<p>Comment line in HTML</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Conditional Comments

This comment is written only for Internet Explorer browser. Other browsers ignore this comment. Conditional instructions are written for different versions of Internet Explorer browser. Do not use it for browsers other than Internet Explorer browser.

<!DOCTYPE html>
<html>
<head>
<!--[if IE 7]>
Special Instructions Goes Here…
<![endif]-->
<p>Comment line in HTML</p>
</head>
</html>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)