HTML <!- -…- -> Tag

In this article, we will be discussing about HTML Tag comment. Trying to meet the learning needs with this content.

An HTML comment:

Example

<!DOCTYPE html> <html> <body> <!--This is a comment. The browser does not display comments--> <p>This is a paragraph.</p> </body> </html>

Here is another example of the comment with code written inside it:

Example: 

<!DOCTYPE html> <html> <body> <!--The code written inside this will not work <h1>Capital Heading</h1> <p>This for the example that it will not work</p> --> <p>This is a paragraph.</p> </body> </html>


Uses and Definition

In the source code, comments are inserted using the tag comment. Browsers do not display comments.

Can use Comments to clarify your code, which can be helpful when editing the source code later. Coders with a lot of code will particularly benefit from this.

By using the comment tag, you can “hide” scripts from browsers without script support (so they won’t appear as simple text) in tag comment:

<script type=”text/javascript”>
<!–
function displayMsg()
{
alert(“This is Alert Document”)
}
//–>
</script>
Please note: JavaScript comment symbols are the two forward slashes at the end of comment lines (//). Cannot execute –> tags in JavaScript because of this.

Browser Compatibility

Element
<!–…–>YesYesYesYesYes

Event Attributes

There are no event attributes accepted in the tag comment.

Here are more details about Event Attributes.


Standard Attributes

There are no standard attributes included in the tag comment.

Here is more information about Standard Attributes.


Advantages of using HTML Tag Comment

HTML tag comments have several advantages, including:

  1. Comments help developers to organize their code and make it easier to read and understand. By including comments, you can explain their code to other developers or remind themselves of what the code does.
  2. When code isn’t working as expected, comments can be used to isolate the problem. You can comment out code to see if it’s causing the issue, or add comments to identify where the issue may be occurring.
  3. When multiple developers are working on a project, comments can help them communicate and coordinate their efforts. Comments can provide context for code changes, explain why certain decisions were made, or highlight areas that need further work.
  4. Comments can be used to create documentation for a project. By including comments that explain how code works or how to use certain functions, you can make it easier for others to work with their code.
  5. Comments can help with code maintenance by making it easier to update or modify code. By including comments that explain how code works, you can quickly understand what changes need to be made and why.


Do subscribe to our Newsletter below, if you want to get connected with the latest technical information on this site.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

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