Last Updated on January 23, 2021 by Roshan Parihar
In this tutorial, learn how to write HTML comments and how to comment HTML codes? The short answer is: use the HTML starting tag <!--
and the closing tag -->
with content inside to add as a comment.
While writing HTML codes, you may want to write HTML comments to easily understand the codes. Adding comments in HTML codes for each line describes the purpose of adding the code. This is the best way of coding for developers and programmers.
What is HTML Comment
HTML Comments are the lines visible only in the codes and not in the frontend to the users. This means, there is no effect in the view of your page. These are used to explain the purpose of adding markup codes.
You can find each section of code easy to understand when using the comments in HTML. You can easily analyze the source code in just one single view of comments.
How to Write HTML Comments?
To write comments in HTML, you have to add the text inside the starting tag <!--
and the end tag -->
. You can add texts as well as the HTML codes inside the comment tags.
1 |
<!--Commented text will comes here--> |
This is the single-line comment in HTML. However, if you want to add the multiline comments in HTML. You don’t need to use any other tags and can use the same tag as given above.
To add the multiline HTML comments in HTML codes, check the example given below. The below example contains the commented heading and the paragraphs. You can comment on these line of HTML codes using the same starting tag <!--
and end tag -->
.
1 2 3 4 5 |
<!-- <h2>This is the heading in HTML</h2> <p>This is paragraph in HTML.</p> <span>This is the span tag in HTML.</span> --> |
If you want to add as many lines as you want, they all should come under the comment tags given above will consider as HTML comments. You can add an HTML tag inside the HTML comments to make them commented.
You May Also Like to Read
I hope you like this tutorial on how to write comments in HTML.
Reference