HTML 段落或 HTML p 标签用于定义网页中的段落。让我们通过一个简单的示例来看看它是如何工作的。需要注意的是,浏览器会在段落之前和之后自动添加空行。HTML <p> 标签表示新段落的开始。

注意:如果在一个 HTML 文件中使用多个 <p> 标签,则浏览器会在两个段落之间自动添加一个空行。

示例:

<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the third paragraph.</p>

输出:

This is the first paragraph.

This is the second paragraph.

This is the third paragraph.

HTML 段落中的空格

如果在 HTML <p> 标签中放入了很多空格,浏览器在显示页面时会移除额外的空格和额外的换行。浏览器会将连续的多个空格和换行视为一个空格。

<p>
I am
going to provide
you a tutorial on HTML
and hope that it will
be very beneficial for you.
</p>
<p>
Look, I put here a lot
of spaces          but      I know, Browser will ignore it.
</p>
<p>
You cannot determine the display of HTML
</p>
<p>because resized windows may create different result.</p>

输出:

I am going to provide you a tutorial on HTML and hope that it will be very beneficial for you.

Look, I put here a lot of spaces but I know, Browser will ignore it.

You cannot determine the display of HTML because resized windows may create different result.

如您所见,浏览器移除了所有多余的换行和不必要的空格。

如何在段落中使用 <br><hr> 标签?

HTML <br> 标签用于插入换行,在段落元素中可以使用它。以下是示例,展示如何在 <p> 元素中使用 <br>

示例:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <h2>Use of line break with paragraph tag</h2>
  <p>
    <br>Papa and mama, and baby and Dot,
    <br>Willie and me—the whole of the lot
    <br>Of us all went over in Bimberlie's sleigh,
    <br>To grandmama's house on Christmas day.
  </p>
</body>
</html>

HTML <hr> 标签用于在两个语句或两个段落之间添加水平线。以下是一个示例,展示如何在段落中使用 <hr> 标签。

示例:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <h2>Example to show a horizontal line with paragraphs</h2>
  <p>An HTML hr tag draws a horizontal line and separates two paragraphs with that line.</p>
  <hr>
  <p>It will start a new paragraph.</p>
</body>
</html>

支持的浏览器

元素chrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<p>
<br>
<hr>

标签: html, HTML教程, HTML技术, HTML学习, HTML学习教程, HTML下载, HTML语言, HTML开发, HTML入门教程, HTML进阶教程, HTML高级教程, HTML面试题, HTML笔试题, HTML编程思想