Use of Comments in HTML
×
Home Courses Community Support
Use of Comments in HTML

Comment is generally used by developers to explain their code. It help them to understand, update or edit the code in future. HTML comment plays a big role in web pages which have lot of source code. The code or text written in HTML comment doesn't display in browser.
 

Comment tag is not like other HTML tags. It was created to allow developers to comment their code for easiness and better result. That's why we have no attribute available for comment. A comment in HTML start with <!-- and close -->.
 

Comment can be used as below-

  • Single line comment
<html>
<head><title>My HTML Page</title></head>
<body>
<!-- <p align="center">This is my first webpage.</p> -->
<img src="http://www.geeksdemy.com/images/directaccess/RWD.PNG">
</body>
</html>

 

In the above code we have commented the paragrapf, so it will now display in browser. Check this code in CodeLAB.
 

  • Multiple Line Comment

If we don't want to show the result of more then one line then we use multiple line comment.
 

<html>
<head><title>My HTML Page</title></head>
<body>
<!--
<p align="center">This is my first webpage.</p>
<img src="http://www.geeksdemy.com/images/directaccess/RWD.PNG">
-->
</body>
</html>

 

Now the above code will not display anything on the browser, because we put all the body content in comment.
 

  • Conditional Comment

This type of comment is used to comment some special code which is not supported on all browsers.

<!--[if IE 11]>
   Special instructions for IE 10 here
<![endif]-->

 

 

← Preview

CSS Class in Head Section

Next →

Using List in HTML

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App