文
章
目
录
章
目
录
注释是在代码中编写的一些文本或代码,用于对代码进行解释,对用户不可见。用于 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">