Summary -

In this topic, we described about the below sections -

Comments are self-described. Comment tags used to insert the comments in HTML document. Comments are not displayed by any browser. Mostly comments used to help document HTML. Notifications and remainders can be added by using comments.

Syntax -

<!-- Write your comments here -->

The comments have the following restrictions:

  • The comment start delimiter "<!--"
  • the comment end delimiter "-->"

Comments are used while debugging HTML document.

Example -

<!DOCTYPE html>
<html>
	<head>
		<title>Comment example.. </title>
	</head>
	<body>
		<!--  Below is the paragraph -->
		<p>This is a paragraph.</p> 
	</body>
</html>

Output -

This is a paragraph.

Multiline comments -

Multiline Comments are self-described. Multiline Comment tags used to comment more than one line in HTML document. Multiline Comments are not displayed by any browser.

Syntax -

<!--
    .... some HTML here (multiline) ....
-->

The comments have the following restrictions -

  • The comment start delimiter "<!--"
  • the comment end delimiter "-->"

Example:

<!DOCTYPE html>
<html>
	<head>
		<title>Multiline Comment example.. </title>
	</head>
	<body>
		<p>This is a paragraph1</p>
		<!--  Below is the paragraph commented -->
		<!--
			<pre>This is a paragraph1.
			This is paragraph2.
			This is paragraph3.</pre>
		-->
	</body>
</html>

Output -

This is a paragraph1

Conditional Comments -

Conditional Comments are self-described. Conditional Comment tags used to insert the comments based on the condition in HTML document. Conditional Comments are not displayed by any browser.

The tags in between the conditional comments will be executed by internet explorer only.

Syntax -

<!--[if condition]>
    .... some HTML here ....
<![endif]-->

The comments have the following restrictions:

  • The comment start delimiter "<!--"
  • The comment end delimiter "-->"

Example -

<!DOCTYPE html>
<html>
	<head>
		<title>Conditional Comment example.. </title>
		<!--[if lt IE 8]>>
		<link rel="stylesheet" type="text/css" href="../css/ie.css">
		<![endif]-->
	</head>
	<body>
		<!--  Below is the paragraph -->
		<p>This is a paragraph.</p> 
	</body>
</html>

Output -

This is a paragraph.

Comment Tag -

Comment tag used to comment the part of code in HTML document. Comment tag represented with <comment> tag. Any text in between <comment>..</comment> defines it as comment to browsers. <Comment> element is nested element.

Syntax -

<comment>
    .... some HTML here ....
</comment>

Example -

<!DOCTYPE html>
<html>
	<head>
		<title> Comment tag example.. </title>
	</head>
	<body>
		<!--  Below is the paragraph -->
		<p>This is <comment>commented</comment> text.</p> 
	</body>
</html>

Output -

This is commented text.
Note! Only IE browsers doesn't display the data in between comment tag.
But all other browsers will display the text as usually.