In HTML, comments are used to insert notes or explanations within the code that will not be displayed on the webpage. These comments are helpful for developers to leave messages for themselves or other developers, to clarify sections of code, or to temporarily disable certain parts of the HTML code.
How to Write an HTML Comment:
HTML comments start with <!-- and end with -->. Anything placed between these tags will be treated as a comment and will not be rendered by the browser.
Example of an HTML Comment:
html
<html>
<head>
<title>HTML Comment Example</title>
</head>
<body><!– This is a comment. It will not be displayed on the webpage. –>
<h1>Welcome to My Website</h1>
<!–
The following paragraph is a description of the website.
This is another comment that spans multiple lines.
–>
<p>This website is designed to provide information about HTML and web development.</p>
<!– <p>This is a hidden paragraph. The browser will ignore this line because it is commented out.</p> –>
</body>
</html>
Key Points:
- Single-line Comments: Place the comment on one line, starting with
<!--and ending with-->. - Multi-line Comments: You can comment out multiple lines by placing
<!--at the start and-->at the end of the comment block. - Temporarily Disabling Code: You can use comments to temporarily disable parts of the code by wrapping them in comment tags, which is useful for debugging or testing.
HTML comments are not visible to users who visit the website but can be viewed in the page’s source code.
