Site icon TestingDocs.com

HTML Comments

Overview

The HTML comments tag is used to add 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 are meant for others to understand the code better. Comments 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. Example of multi-line comment 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. There is a space in the comment start tag between angle bracket and exclamation mark.

–>

Invalid comments will be displayed in the browser.

HTML Tutorials

HTML Tutorials on this website:

https://www.testingdocs.com/html-tutorials/

More Information on HTML:

https://www.w3.org/TR/html401/intro/intro.html

Exit mobile version