注释是在您的代码中编写的一些文本或代码,用于对代码进行解释,并且对用户不可见。用于 HTML 文件的注释称为 HTML 注释。浏览器将忽略这些标签之间的任何内容,因此网页上将看不到评论。
任何代码的注释都使代码易于理解并提高代码的可读性。
注释也是代码的一部分,它给出了代码的解释。
您可以使用 <! -- ... --> 标签。因此,如果您在这些评论标签之间写任何内容,将被视为评论,浏览器将不会读取它。
<! -- Write commented text here -->
如:
<!-- <p>There is some text</p> <p>There is second text</p> -->
<!DOCTYPE html>
<html>
<!-- This is Header section -->
<head>
<!-- Internal CSS -->
<style>
body{
text-align: center;
background-color: #f0f8ff;
font-size: 30px;
color: red;
}
</style>
</head>
<!-- This is body section, write code here which you want to display on web-page -->
<body>
<!-- heading tag -->
<h2>First WebPage</h2>
<!-- Paragraph tag -->
<p>Write your Content here!!!</p>
</body>
</html>在 HTML 代码中,我们也可以一次注释多行。在多行注释中,我们可以使用任何关于代码的描述或多行代码来调试等。
<!--- Your code is commented. Write description of code. It will not display at webpage. -->
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align: center;
background-color: #98f5ff;
}
</style>
</head>
<body>
<h2>Cake Gallery</h2>
<!-- This is image for a yummy cake
you can see it on your web-page
of your favorite browser -->
<img src="https://www.rocschool.com/public/uploads/images/20210629/91451624933787.png" alt="cake image" height="300px" width="300px">
</body>
</html>输出:

| 元素 | Chrome | IE | Firefox | Safari | Opera |
|---|---|---|---|---|---|
| <!-- --> | Yes | Yes | Yes | Yes | Yes |