HTML Comments
HTML Comments
The HTML comments tag adds a comment to the HTML code. The web browser ignores the comment. We can use the comment tags to explain the HTML code, program documentation, author information, license header, etc.
The text in the HTML comment tag will not be displayed on the web page. Comments help others understand the code better and increase code readability.
HTML Comments Syntax
<!– HTML comment here –>
Comments start with <!– tag and end with –>
Example
<html>
<body>
<h1> Hi, How are you?</h1>
<br>
<!– Sample HTML comment –>
<!– This two lines are not displayed on the browser –>
<h2>Welcome to www.TestingDocs.com</h2>
</body>
</html>
HTML Editor generally highlights the comments in different color text.
Lines 7, 8 are comments in the code. The comments are single-line comments. They start with <!– tag and end with –> tag.
Sample Output
Multiline Comments
Comments can span across multiple lines. An example of multi-line comment is shown below:
<!– Sample HTML comment
Example of Multi-Line long HTML
Comment.
–>
We can even decorate the comment tag with extra characters. For example, to display a box-like comment box.
<!–
####################################
# Program Author:
# Date :
# Display greeting to user.
#
# Revision History: Initial Draft.
#
# Review Comments:
#
####################################
–>
Common Error
The most common error is using spaces in the comment tags. For example,
< !–
This is an invalid HTML comment. The comment start tag has a space between the angle bracket and the exclamation mark.
–>
Invalid comments will be displayed in the browser.
—
HTML Tutorials
HTML Tutorials on this website:
https://www.testingdocs.com/html-tutorials/
More HTML information:
https://www.w3.org/TR/html401/intro/intro.html