总结
HTML的<p>元素(或者HTML段落元素)表示一个段落。段落是块级元素。
- 内容分类 Flow content, palpable content.
- 允许的内容 Phrasing content.
- 标签省略起始标签是必需的,结束标签在以下情形中可以省略。<p>元素后紧跟{{HTMLElement("address")}}、{{HTMLElement("article")}}、{{HTMLElement("aside")}}、{{HTMLElement("blockquote")}}、{{HTMLElement("div")}}、{{HTMLElement("dl")}}、{{HTMLElement("fieldset")}}、{{HTMLElement("footer")}}、{{HTMLElement("form")}}、{{HTMLElement("h1")}}、{{HTMLElement("h2")}}、{{HTMLElement("h3")}}、{{HTMLElement("h4")}}、{{HTMLElement("h5")}}、{{HTMLElement("h6")}}、{{HTMLElement("header")}}、{{HTMLElement("hr")}}、{{HTMLElement("menu")}}、{{HTMLElement("nav")}}、{{HTMLElement("ol")}}、{{HTMLElement("pre")}}、{{HTMLElement("section")}}、{{HTMLElement("table")}}、{{HTMLElement("ul")}} 或另一个{{HTMLElement("p")}}元素;或者父元素中没有其他内容了,而且父元素不是{{HTMLElement("a")}}元素
- 允许的父元素任何接受flow content的元素
- DOM接口 {{domxref("HTMLParagraphElement")}}
属性
这个元素包含全局属性。
在{{HTMLVersionInline(5)}}中,<p>元素的align属性{{obsolete_inline}}。
示例
<p>This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text.</p> <p>This is second paragraph of text. This is second paragraph of text. This is second paragraph of text. This is second paragraph of text.</p>
以上的HTML输出如下:
This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text.
This is second paragraph of text. This is second paragraph of text. This is second paragraph of text. This is second paragraph of text.
注意
使用CSS {{cssxref("margin")}}属性去改变段落之间的间隙,不要在段落之间插入空的段落元素或者{{HTMLElement("br")}}元素。
规范
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'grouping-content.html#the-p-element', '<p>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'grouping-content.html#the-p-element', '<p>')}} | {{Spec2('HTML5 W3C')}} | |
{{SpecName('HTML4.01', 'struct/text.html#h-9.3.1', '<p>')}} | {{Spec2('HTML4.01')}} |
浏览器兼容性
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
另请参阅
- {{HTMLElement("hr")}}
- {{HTMLElement("br")}}
{{HTMLRef}}