Select Page


HTML Comment: Learn How & Why To Add Comments In HTML

Vinit Patil,Freelance Developer

17 November 2017

Adding Comments to your HTML Code is really helpful. Many of you web developers might be really good at html But you still don’t know how to add comments in HTML.

Why Should You Add Comments In HTML

Adding or not adding comments in your html source code doesn’t make any difference in the performance or execution of your html code.

But if you write thousands of lines of html code or write some html code which is very complicated and you are trying to modify the html source code. To do it you need to understand your code whole again from the start which is not an easy task and will consume lots of your precious time. Therefore to solve this issue you need to use html comments so that you don’t waste your precious time.

Adding comments to your code is a good practice. They will help while modifying your website.

HTML Comment Tag <!- -…- ->

The HTML Comment Tag is used to add comments to the html source code

Example Of an HTML Comment :-


<!– I am a comment , You can only See me in the source code and not in the browser –>

<p> Learning how to add comments to html code </p>


HTML Comment is a piece of your code that is completely ignored by the web browsers. So you can write anything you want within your comments.

You can also add reminders for yourself by using html comment.


<p> This is my paragraph </p>

<!– I have to add some more stuff here –>



Debugging Your Code With HTML Comment

Debugging your html code is one of the toughest tasks. Therefore you sometimes have to remove some piece of code from your html code. But sometimes you might end up losing the removed piece of code !!

Hence, you need to use html comments so that you comment out the piece of code you want to remove instead of actually removing it.

Here’s how you can do it.



<p> I don’t want this piece of code to run in the browser. Therefore I have disabled it </p>



Using Comments For Hiding Scripts From Un Supported Browsers

Sometimes your website might be opened in a browser that doesn’t support javascript. Therefore you can do something like this for solving it –


<script type=”text/javascript”>


document.write(“Hello, I will be Commented In Unsupported Browsers”);




HTML Comment Browser Support

Don’t Worry Comments Are Supported in All Browsers !!

[table id=14 /]

I hope you may have understood html comments. If you have any doubts don’t hesitate to ask me in the comments section below.

And don’t forget to like this post and also share it with your other web developer friends.

Want new articles before they get published?
Subscribe to our Awesome Newsletter.

Need Help? Chat with us
Share This