Comments In HTML

We are examining Html comments with examples. HTML comments are useful for documenting your HTML source code but are hidden from the browser.

A comment is a line of code that is not read by web browsers. To indicate sections of a document, as well as any other notes to anyone looking at the code, it is helpful to add comments to your HTML code. Code comments improve readability and help you and others understand your code.

HTML Comment Tags

The following syntax can be used to add comments to your HTML source code:

Example

<!DOCTYPE html> <html> <body><!-- This is how to insert comment in HTML code --></body> </html>

You will notice that the start tag has an exclamation point(!), but the end tag does not.

It is important to note that the browser does not show comments, but it can help document your HTML source code.

Your HTML code can include information and reminders with comments when it comes to Html comments:

Example

<!DOCTYPE html> <html> <body><!-- This is a comment text--> <p>And this is a paragraph.</p> <!-- Add more comments here --></body> </html>

Multiline Comment

By using HTML code, we can render comments on multiple lines at the same time. With these multiline comments, it is possible to provide explanations about particular codes or multiple line codes that can be used for debugging purposes and so on.

Syntax

<!—

You have commented your code.

Describe the code in detail.

There will be no display on the webpage.

–>

Example: 

<!DOCTYPE html> <html> <body> <h2>Jeff Bezos</h2> <!-- born January 12, 1964 Children: Preston Bezos Spouse: MacKenzie Scott (m. 1993--2019) --> <p>Jeffrey Preston Bezos is an American entrepreneur, media proprietor, investor, and commercial astronaut. He is the founder, executive chairman, and former president and CEO of Amazon.</p> </body> </html>

Commenting Style Sheets

The use of style sheets with HTML will be covered in another tutorial, but at the moment you should be aware that if you are using Cascading Style Sheets (CSS) in your HTML code, you should place the style sheet code within HTML comments so that old browsers will be able to see it.

Example: 

<!DOCTYPE html> <html> <head> <title>Style sheet comment</title> <style> <!-- .main { background-color:#4a7d49; } --> </style> </head> <body> <div class="main">This is a main div</div> </body> </html>

For this reason, comments are extremely useful for debugging HTML since they authorize you to examine for bugs by separately commenting out HTML lines of code:

Example

<!DOCTYPE html> <html> <body><!-- We are not displaying this image at the moment <img border="0" src="pic_trulli.jpg" alt="Trulli"> --></body> </html>

Conclusion

Adding HTML comments to web pages can help web developers keep track of notes, reminders, and other information. HTML comments make it easy to track your code, collaborate with other developers, and improve the quality of your web content.

HTML comments can also be used to temporarily remove code from your web page without removing it entirely. You can use this for troubleshooting and testing your web content.

Adding comments to HTML allows web developers to create code that is cleaner, more efficient, and better organized.

Make sure you make use of HTML comments the next time you are creating a web page to enhance the quality of your content and improve your workflow.

If this article somehow met your educational needs, do share it with your friend developers using the platforms as facebook,twitter and etc below.
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

6 thoughts on “Html Comments Complete Guide with Examples

  1. Great post. I was checking constantly this weblog and I’m inspired!
    Very useful info particularly the ultimate part 🙂 I deal with such
    info much. I was seeking this certain information for a very long time.
    Thanks and best of luck.

  2. Unquestionably believe that that you stated.

    Your favorite justification appeared to be on the internet the simplest thing to keep in mind of.

    I say to you, I definitely get irked while people think about issues that they just do not know about.
    You controlled to hit the nail upon the highest as well as
    outlined out the entire thing without having side-effects , people can take
    a signal. Will probably be again to get more. Thank you

  3. Howdy I am so excited I found your web site, I really found you by accident, while I was
    searching on Askjeeve for something else, Nonetheless I am here now and would just like
    to say kudos for a incredible post and a all round thrilling blog (I also love the theme/design), I don’t have time to read through it all
    at the minute but I have bookmarked it and
    also included your RSS feeds, so when I have time I will be
    back to read much more, Please do keep up the fantastic job.

  4. Bravo! Your article doesn’t just educated me on this subject
    but additionally instilled inspiration for deeper investigation into the subject.
    Keep up the excellent work!

  5. Informative and useful – that’s what I appreciate about your blog posts.
    This one on this topic is no different. The suggestions and advice you offer are actionable and make a significant impact.

Leave a Reply

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