HTML Comments-for beginners

  • Comments is a piece Of code which is ignored by any web browser.
  • It is a good practice to add comments into your HTML code, to indicate sections of a document and other notes to anyone looking at the code.
  • Comments help you and others understand your code and increases code readability.
  • HTML comments are placed in between <!--..--> tags. So any content placed with- in <!--…-->tagswill be treated as comment and be completely ignored by the browser.

Example of comment;

<!DOCTYPE html>
<html>
                <head>
                                <title> this is document title<?title>
                </head>
                <body>
                                <!--single line comment-->
                                <!—this is a multiline comment and it can span through as many as lines you like-->
                                <p> document content goes here……  </p>
                </body>
</html>

This will produce following result without displaying the content given as a part of comments:

Output
Document content goes here……. 

Mult-line comment:
You can comment multiple lines by the special beginning tag <!—and ending tag--> placed begore the first line and end of the last line as shown in the given example below.

<!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.
-->
<p> Document content goes here……
</body>
</html>

Output
Document content goes here……..


Important Notes:
  • Comments do not nest which means a comment cannot be put inside another comment.
  • The double-dash sequence “—  “ many not appear inside a comment except as part of the closing --> tag.
  • You must also make sure that there  are no spaces in the start-of-comment string.


Prepared by IBRAHIM MCHUCHURI


HTML Comments-for beginners HTML Comments-for beginners Reviewed by Unknown on May 11, 2017 Rating: 5

No comments

Random Posts

3/random/post-list