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
支持 支持 支持 支持 支持