个性化阅读
专注于IT技术分析

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.srcmini02.com/htmlpages/images/cake.png" alt="cake image" height="300px"
  width="300px">

立即测试

输出:

HTML注释

支持的浏览器

Element Chrome IE Firefox Opera Safari
<!– –> Yes Yes Yes Yes Yes
赞(0)
未经允许不得转载:srcmini » HTML注释

评论 抢沙发

评论前必须登录!