Comments and Tags in HTML

Comments and Tags in HTML

Table of contents

No heading

No headings in the article.

Hello Friends! In today's blog, we'll learn how to put comments and tags in your HTML document.

What is a comment? A comment is a statement that helps you understand the program better. It doesn't appear in the output.

There are the following types of comments:

  • Single-line and Multiline comments- It is represented by <!------------ >. Both single and multiple lines are allowed.

    Example- Single-line comment.

<html>
<head>
</head>
<body>
       <!--This is a single-line comment-->   
</body>
</html>

Example - Multiline comment

<html>
<head>
</head>
<body>
   <!--This is a multi-line comment
      Here, the content can be added 
      in multiple lines.-->
</body>
</html>
  • Comment tag- It is represented by <comment>. A comment tag allows you to add a comment to your document.
    <html>
    <head>
    </head>
    <body>
      <comment>
          Hello, Folks!
      </comment>
    </body>
    </html>
    

What are tags?

A tag allows the formatting of the data accordingly. A tag is an opening tag as well as a closing tag.

  1. open tag - <a>
  2. close tag - </a>

A closing tag includes a backslash.

There are various types of tags. Some of them are listed below:

  • <head> - It contains the specific information of a website.

Input-

<head>
    <h1>Hello</h1>
    <h2>Hello</h2>
    <h3>Hello</h3>
    <h4>Hello</h4>
    <h5>Hello</h5>
    <h6>Hello</h6>
</head>

Output-

Hello

Hello

Hello

Hello

Hello
Hello
  • <body>- It contains the main content of a website.

Input-

<html>
<head>
</head>
<body>
    Hello everyone, I'm Anshika. We are learning about tags.   
</body>
</html>

Output-

Hello everyone, I'm Anshika. We are learning about tags.
  • <p>- Sometimes, you add paragraphs to your document. For this, <p> tag is used. It ignores all the extra spaces given to the context.

Input

<html>
<head>
</head>
<body>
    <p>Hello everyone, I'm Anshika. We are learning about tags.  
             This is paragraph tag.</p> 
</body>
</html>

Output-

Hello everyone, I'm Anshika. We are learning about tags.
This is paragraph tag.

  • <br>- It is a line break element.

Input-

<html>
<head>
</head>
<body>
    We are learning about break tag.
    <br>
    Tags are easy to learn.
</body>
</html>

Output-

We are learning about break tag.
Tags are easy to learn.
  • <hr>- It is a horizontal break element. It displays a horizontal line in the output. Input-
    <html>
    <head>
    </head>
    <body>
      We are learning about break tag.
      <hr>
      Tags are easy to learn.
    </body>
    </html>
    

Output-

We are learning about break tag.
Tags are easy to learn.

NOTE: <br> and <hr> have no closing tags.

  • <pre>- This tag represents the text as it is.

Input-

<html>
<head>
</head>
<body>
    <pre>We are learning about break tag.
        Tags are easy to learn.
        </pre>

</body>
</html>

Output-

We are learning about break tag.
        Tags are easy to learn.
        

Conclusion: In today's blog, we got to know about comments and tags.