In HTML, comments are used to add notes or explanations in the code that will not be displayed in the browser. They are helpful for developers to leave reminders, explanations, or disable certain parts of the code temporarily.
Syntax for an HTML Comment:
html
<!-- This is a comment -->
Example:
html
<html>
<head>
<title>My Web Page</title>
<!-- This is the title of the web page -->
</head>
<body>
<h1>Welcome to my website</h1>
<!-- This paragraph is hidden and won't appear in the browser -->
<!-- <p>This content is commented out and will not be displayed.</p> -->
<p>This is a visible paragraph.</p>
</body>
</html>
Key Points:
- Comments will not be visible to users viewing the webpage.
- Comments can span multiple lines.
- You can use comments to disable sections of HTML temporarily for testing or debugging.
