How to Comment out in HTML

In this article, we will discuss how to add insert both single-line and multi-line comments into your HTML documents. I’ll provide some tips and best practices for using comments effectively in your HTML code.

Commenting out code can be useful in a variety of situations. Like, you might want to temporarily disable a block of code that is causing problems, or you might want to leave notes or reminders for yourself or other developers.

When you add comments to your HTML source code, they will not be displayed in a web browser. This implies that any comments you make will not be visible when the document is rendered in a web browser.

Syntax for HTML comments

To create comments in HTML, use the symbols. The text you want to comment-out should be enclosed by these symbols.

Be sure to include the exclamation mark at the beginning of the tag. However, there is no need to add it at the end.

How to Write Single-Line Comments in HTML

A single-line comment is restricted to one line only, and as mentioned before, that line will not be shown in the browser. A single-line comment is beneficial when you want to explain and clarify the purpose of the code.

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>How to comment out in html 100 volume</title>
   </head>
   <body>
      <body>
         <!-- Add the menu here -->
         <h2>Home</h2>
         <h2>About me</h2>
         <h2>Contact US</h2>
   </body>
</html>

You can also use the single-line comments in a long and complex HTML document to notify where the tag ends.

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>How to comment out in html 100 volume</title>
   </head>
   <body>
       <!-- start body -->
      <body>
         <!-- Add the menu here -->
         <h2>Home</h2>
         <h2>About me</h2>
         <h2>Contact US</h2>
   </body>
   <!-- end body -->
</html>

How to Write Inline Comments in HTML

You can also add comments in the middle of a sentence or line of code.

However, only the text enclosed by will be commented out, and the remaining text inside the tag will remain unaffected.

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>How to comment out in html 100 volume</title>
   </head>
   <body>
      <body>
         <p>I am <!-- name --> parvez</p>
         <h2>Home</h2>
         <h2>About me</h2>
         <h2>Contact US</h2>
   </body>
</html>

How to Write Multi-Line Comments in HTML

Comments can also span multiple lines, using the exact same syntax you’ve seen so far.

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>How to comment out in html 100 volume</title>
   </head>
   <body>
      <body>
         <h2>Home</h2>
         <h2>About me</h2>
         <h2>Contact US</h2>
		 <!-- You can also add multiple menu option here.
			add social widget-->
   </body>
</html>

How to Comment Out a Tag in HTML

You can also comment-out html tag in your html file. You wrap the html tag as like below:

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>How to comment out in html 100 volume</title>
   </head>
   <body>
      <body>
         <!--<p>I am testing comment tag</p>-->
         <h2>Home</h2>
         <h2>About me</h2>
         <h2>Contact US</h2>
   </body>
</html>

Conclusion

I have commented out code in HTML in a variety of ways. This is a simple process that can be very helpful in a variety of situations. Commenting helps to make your code more readable and maintainable. This article will provide you with the knowledge to insert both single-line and multi-line comments into your HTML documents.

Leave a Reply

Your email address will not be published. Required fields are marked *