HTML教程-HTML注释

注释是在您的代码中编写的一些文本或代码,用于对代码进行解释,并且对用户不可见。用于 HTML 文件的注释称为 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.
-->
例子:
<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://static.javatpoint.com/htmlpages/images/cake.png" alt="cake image" height="300px"
width="300px">
输出: