HTML Comments

Next Page Previous Page

The comment makes the comment section hidden from the browser, developers can use it to add some points and notes to the code or sometimes hide some code and test the rest.

 

Syntax: <!-- comment text -- >

Simple Comment:

<!DOCTYPE html>
<html>
	<head>
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
		 
		 <!-- comment will not be displayed on web page -->

	</body>
</html>

Comments between other code :

<!DOCTYPE html>
<html>
	<head>
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
		 
		 <!-- comment will not be displayed on web page -->
		 <p>Browser will read this paragraph and ignore comments around it </p>
		 <!-- comment will not be displayed on web page -->

	</body>
</html>

 

Multi-line comments :

<!DOCTYPE html>
<html>
	<head>
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
		 
		 <!-- Hello there i am adding a multi-line command
		 here to see how it works,
		 and if my browser reads this 
		 or ignore this like 
		 single line comment !
		 -->
	</body>
</html>

 

Commenting bunch of code:

<!DOCTYPE html>
<html>
	<head>
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
		 <!--
		 <table style="width:100%">
		  <tr>
			<th>A</th>
			<th>B</th>
			<th>C</th>
		  </tr>
		  <tr>
			<td>1</td>
			<td>2</td>
			<td>3</td>
		  </tr>
		  <tr>
			<td>4</td>
			<td>5</td>
			<td>6</td>
		  </tr>
		</table>
		-->	 
	</body>
</html>

Using comments as little notes and reminders:

<!DOCTYPE html>
<html>
	<head>
	<!-- This is head of our HTML document  -->
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
		<!--I am here to remind you that you are supposed to write the main body pints here !-->
	</body>
</html>

 

Conditional comment : 

The downfall of conditional comments is that it only works on Internet Explorer, the rest of the browser just ignores these comments like a normal comment.

<!DOCTYPE html>
<html>
	<head>
		<!--[if IE 6]>
         Special instructions for IE 6 here
        <![endif]-->
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
		<!--I am here to remind you that you are supposed to write the main body pints here !-->
	</body>
</html>

Comment Tag <comment>: comment tag is also outdated, in HTML 5 it's no more in use, and apart from internet explorer other browsers can read this.

<!DOCTYPE html>
<html>
	<head>
		<title>HTML Comments </title>
	</head>
	<body>
		 <label>these are some Comments</label>
			<comment> Hello from comment tag !</comment>
	</body>
</html>
Next Page Previous Page

Treding Tutorial

Popular Tutorials

to Learn now