Skip to main content

HTML Comment Tags

By SamK
0
0 recommends
Category(s)
Topic(s)

HTML comment tags <!-- --> are used to document the HTML code.

They are not visible in the browser.

<!-- This is an HTML comment -->

You can use comments to add notifications and reminders in your HTML code.

<!-- This is a comment -->
<h2>This is a heading.</h2>
<!-- Todo: A description is needed here --> 

Comments can also be used to temporarily hide content, which can be helpful in some cases, for example, if you want to test different versions of the same element. For example, 

<p>This is a first paragraph.</p>
<!-- <p>This is a hidden second paragraph.</p> -->
<p>This is a visible version of the second paragraph.</p> 

You can also hide multiple lines of content using one pair of comment tags.

Everything between <!-- and --> will not be displayed.

<p>This is a paragraph.</p>
<!--
<h2>This is a hidden heading</h2>
<p>This is a hidden paragraph.</p>
-->
<p>This is a paragraph too.</p> 

Comments can also be used inline in other HTML tag, for example:

 <p>This <!-- hidden text --> is a paragraph.</p>

Comments form an integral part of a well-documented and properly written code.