HTML comment tag is used to insert comments inside source code. Contents within comment (<!–..–>) tag will not be displayed in web browsers.
Writing comments inside source code is a good practice because it becomes difficult to review or remember your code especially when you are working with thousand lines of code. It helps you to explain or review your source code so that you can easily get and understand or/and edit your source code later on.
Note: HTML comment tag does not support any HTML Attributes.
Following are the types of comments that are supported by HTML document.
HTML Comment – Description
HTML comment starts with “<!–“ and ends with “–>” (without quotes).
<title> HTML Comment Tag Example</title>
Body Part Starts this is a
valid comment statement
<p> This is an example code for HTML Comment Tag </p>
<!– Body Part Ends –>
<!– both above comment statements will not display in web browsers –>
Note: It does not support “–“ or “>” anywhere inside comment tag.
This is an example code for HTML Comment Tag
CSS Comment – Description
CSS comment starts with “/*” and ends with “*/” (without quotes).
text-align: left; /* setting paragraph's text align to left */
padding: 5px; /* padding paragraph to 5px from top, right, bottom, left */
This is an example code CSS Comments
1. Single Line Comment: Supports only single line comment which starts with “//” and ends when line ends
2. Multi Line Comment: Supports multiline comment which starts with “/*” and ends with “*/” (without quotes)
// Example of Single Line Comment
document.write("<p>This is a simple example for single line comment</p>");
Example of Multi Line Comment
this is the second line for multi line comment
this is the third line for multi line comment
document.write("<p>This is a simple example for multi line comment</p>");
This is a simple example for single line comment
This is a simple example for multi line comment