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

Leave a Reply

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