Comments are an essential part of HTML; it helps to provide the details of what is written in the HTML source code. HTML comment tags are completely ignored to display by the browsers. It's used to insert comments into the source code.
- When more than one developers work on the same application or web page, HTML comments can help to understand the source code.
- Comment can be used anywhere to add information about HTML, which will be helpful for developers to understand the existing code in the future easily.
Writing Comments in HTML
For writing comments in HTML, they begin with the <! -- (starting comment tag) and ends with the close comment tag, i.e. -->. Comments in HTML can be visible if and only if anyone tries to view the source code of the page, but anything is written within <!-- …. --> does not get rendered when you will render your HTML based web page through your browser.
<!-- This is a commented code -->
<!DOCTYPE html> <html> <head> <title>Example for comment.</title> </head> <!-- Body of webpage starts from here --> <body> <h2>This is HTML comment example</h2> <p>This is my first <strong>paragraph text</strong>.</p> </body> </html>