Follow The New Tutorial updates on WhatsApp, Telegram or YouTube.

How to Comment in Html?

In this tutorial, we are going to explore how to write comments in HTML. Comments are not displayed by the browser.

Here is the syntax for a basic HTML comment tag:

<!-- This is a comment. 
When our web page is opened, this code will not appear on our web page. 
Instead, the code will appear in our source code for us to read.-->

Notice that there is an exclamation point (!) in the start tag, but not in the end tag.

Syntax is same for single line and multiple line comment in HTML.

HTML comments are notes to keep HTML code organized.

HTML comments are ignored by the browser.

HTML Comment Example

<!DOCTYPE html>
<html>
<body>

<p>This is a paragraph.</p>

<!-- <p>This is another paragraph </p> -->

<p>This is a paragraph too.</p>

</body>
</html>

Output of HTML Comment Example

Output of HTML Comment Example
Output of HTML Comment Example

Why should you use comment?

Writing comments allows you to make your code more readable and explain what specific parts of a program are doing. Comments can also help speed up the development process because it is easier for you to understand your code.

When should you add comments to your code?

  • To describe the intended outcome of code.
  • To explain why code has been written.
  • Comments can be used to hide parts in the middle of the HTML code.
  • To clarify a complex line or lines of code.