HTML <p> 标签

定义和用法

<p> 标签定义段落。

浏览器会自动在每个 <p> 元素前后添加一个空行。

提示:请使用 CSS 设置段落样式

另请参阅:

HTML 教程:HTML 段落

HTML DOM 参考手册:Paragraph 对象

实例

例子 1

像这样标记段落:

<p>这是段落中的一些文本。</p>

亲自试一试

例子 2

对齐段落中的文本(使用 CSS):

<p style="text-align:right">这是段落中的一些文本。</p>

亲自试一试

例子 3

使用 CSS 设置段落样式:

<html>
<head>
<style>
p {
  color: navy;
  text-indent: 30px;
  text-transform: uppercase;
}
</style>
</head>
<body>

<p>China, officially the People's Republic of China (PRC),is a country in East Asia. It is the world's second-most-populous country, with a population exceeding 1.4 billion. China spans the equivalent of five time zones and borders fourteen countries by land.With an area of nearly 9.6 million square kilometers (3,700,000 sq mi), it is the third-largest country by total land area. The country is divided into 22 provinces,five autonomous regions, four municipalities, and two semi-autonomous special administrative regions. Beijing is the national capital, while Shanghai is the most populous city and largest financial center.</p>

</body>
</html>

亲自试一试

例子 4

更多段落:

<p>
在源代码中,
这一段
包含很多行,
但浏览器
忽略它。
</p>

亲自试一试

例子 5

HTML 中的诗歌问题:

<p>
  朝辞白帝彩云间,
  千里江陵一日还。
  两岸猿声啼不住,
  轻舟已过万重山。
</p>

亲自试一试

全局属性

<p> 标签还支持 HTML 中的全局属性

事件属性

<p> 标签还支持 HTML 中的事件属性

默认的 CSS 设置

大多数浏览器将使用以下默认值显示 <p> 元素:

p {
  display: block;
  margin-top: 1em;
  margin-bottom: 1em;
  margin-left: 0;
  margin-right: 0;
}

亲自试一试

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持