The HTML comment element is use to add a comment to an HTML document. In HTML document comment elements use to disable code of a page, which you are testing but that is not ready yet. The HTML comment elements begin with <!–– and the comment closes with ––>.
The HTML comment elements are not displayed in the web browser, its use to insert comment in the source code. Follow the HTML comments properly use in your HTML document. For example:
<!DOCTYPE html> <html> <head> <title>HTML – Comments</title> </head> <body> <p><!-- this tag use for paragraph line --></p> </body> </html>
Multiline Comments
Use HTML comment elements you can comment multiple lines text of a HTML page. Comment multiple line text start <!– tag and end –> tag and place text in this tag.
- HTML comment can span multiple line in you HTML document.
- Informative text comments when you explain to the code.
Multiline Comments example:
<!DOCTYPE html> <html> <head> <title>Multiline Comments</title> </head> <body> <!-- This is a multiline comment and it can span through as many as lines you like. --> </body> </html>
Conditional Comments
HTML conditional comments are nothing more than simple HTML comments that will be picked up by Internet Explorer.
- Conditional comments only work in IE.
- Comments between <!–[if IE]> and <![endif]–>.
- A conditional comment block that is ignored by down-level browsers.
Conditional Comments example:
<!DOCTYPE html> <html> <head> <title>Conditional Comments</title> <!--[if IE 6]> Special instructions for IE 6 here <![endif]--> </head> <body> <p>Page content goes here.....</p> </body> </html>
Using Comment Tag
HTML comment tag represents to insert comment in the source HTML code. The HTML comment tag supports few browsers and its start with <comment> tag and end with </comment> tag.
Example:
<!DOCTYPE html> <html> <head> <title>Comment Tag</title> </head> <style type="text/css"> .drop-drown { width: 200px; height: 45px; background: #; border: 1px solid #ececec; } </style> <body> <p style="width: 200px; height: 44px;background: white;border: 1px solid #ececec;">HTML comment tag is <comment>not</comment> support Internet Explorer.</p> </body> </html>
Commenting Script Code
You must make a note that if you are using Java Script in your HTML code. You will give a comment in Java Script using HTML comment. It is recommended to put that script code inside proper HTML page comments.
Example:
<!DOCTYPE html> <html> <head> <title>Commenting Script Code</title> <script> <!-- document.write("Script Code comment") //--> </script> </head> <body> <p>Script Code comment</p> </body> </html>
Commenting Style Sheets
You will learn Style Sheet with HTML for make page document another format and make some design. In HTML you must make a note that if you are using CSS in your HTML document. It is recommended to put that style sheet code inside proper HTML comments.
Example:
<!DOCTYPE html> <html> <head> <title>Commenting Style Sheets</title> <style> /*.example { border:1px solid #4a7d49; }*/ </style> </head> <body> <div class = "example">Example Style Sheets Comment</div> </body> </html>