summaryrefslogtreecommitdiff
path: root/devdocs/html/element%2Fp.html
blob: 5abe191cd08161ca837efed755ea1dc628b49777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<header><h1>&lt;p&gt;: The Paragraph element</h1></header><div class="section-content">
<p>The <code>&lt;p&gt;</code> <a href="../index">HTML</a> element represents a paragraph. Paragraphs are usually represented in visual media as blocks of text separated from adjacent blocks by blank lines and/or first-line indentation, but HTML paragraphs can be any structural grouping of related content, such as images or form fields.</p> <p>Paragraphs are <a href="https://developer.mozilla.org/en-US/docs/Glossary/Block-level_content">block-level elements</a>, and notably will automatically close if another block-level element is parsed before the closing <code>&lt;/p&gt;</code> tag. See "Tag omission" below.</p>
</div>
<h2 id="try_it">Try it</h2>
<div class="section-content">
<iframe class="interactive is-tabbed-standard-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/p.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe> <figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td>
<a href="../content_categories#flow_content">Flow content</a>, palpable content.</td> </tr> <tr> <th scope="row">Permitted content</th> <td>
<a href="../content_categories#phrasing_content">Phrasing content</a>.</td> </tr> <tr> <th scope="row">Tag omission</th> <td> The start tag is required. The end tag may be omitted if the <a href="p" aria-current="page"><code>&lt;p&gt;</code></a> element is immediately followed by an <a href="address"><code>&lt;address&gt;</code></a>, <a href="article"><code>&lt;article&gt;</code></a>, <a href="aside"><code>&lt;aside&gt;</code></a>, <a href="blockquote"><code>&lt;blockquote&gt;</code></a>, <a href="details"><code>&lt;details&gt;</code></a>, <a href="div"><code>&lt;div&gt;</code></a>, <a href="dl"><code>&lt;dl&gt;</code></a>, <a href="fieldset"><code>&lt;fieldset&gt;</code></a>, <a href="figcaption"><code>&lt;figcaption&gt;</code></a>, <a href="figure"><code>&lt;figure&gt;</code></a>, <a href="footer"><code>&lt;footer&gt;</code></a>, <a href="form"><code>&lt;form&gt;</code></a>, <a href="heading_elements">h1</a>, <a href="heading_elements">h2</a>, <a href="heading_elements">h3</a>, <a href="heading_elements">h4</a>, <a href="heading_elements">h5</a>, <a href="heading_elements">h6</a>, <a href="header"><code>&lt;header&gt;</code></a>, <a href="hgroup"><code>&lt;hgroup&gt;</code></a>, <a href="hr"><code>&lt;hr&gt;</code></a>, <a href="main"><code>&lt;main&gt;</code></a>, <a href="menu"><code>&lt;menu&gt;</code></a>, <a href="nav"><code>&lt;nav&gt;</code></a>, <a href="ol"><code>&lt;ol&gt;</code></a>, <a href="pre"><code>&lt;pre&gt;</code></a>, <a href="search"><code>&lt;search&gt;</code></a>, <a href="section"><code>&lt;section&gt;</code></a>, <a href="table"><code>&lt;table&gt;</code></a>, <a href="ul"><code>&lt;ul&gt;</code></a> or another <a href="p" aria-current="page"><code>&lt;p&gt;</code></a> element, or if there is no more content in the parent element and the parent element is not an <a href="a"><code>&lt;a&gt;</code></a>, <a href="audio"><code>&lt;audio&gt;</code></a>, <a href="del"><code>&lt;del&gt;</code></a>, <a href="ins"><code>&lt;ins&gt;</code></a>, <a href="map"><code>&lt;map&gt;</code></a>, <a href="noscript"><code>&lt;noscript&gt;</code></a> or <a href="video"><code>&lt;video&gt;</code></a> element, or an autonomous custom element. </td> </tr> <tr> <th scope="row">Permitted parents</th> <td> Any element that accepts <a href="../content_categories#flow_content">flow content</a>. </td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/structural_roles">paragraph</a></td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>Any</td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLParagraphElement"><code>HTMLParagraphElement</code></a></td> </tr> </tbody> </table></div></figure>
</div>
<h2 id="attributes">Attributes</h2>
<div class="section-content">
<p>This element only includes the <a href="../global_attributes">global attributes</a>.</p> <div class="notecard note" id="sect1"> <p><strong>Note:</strong> The <code>align</code> attribute on <code>&lt;p&gt;</code> tags is obsolete and shouldn't be used.</p> </div>
</div>
<h2 id="examples">Examples</h2>

<h3 id="html">HTML</h3>
<div class="section-content"><div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="FbcvsC38VNKV5rvL7IZ3SMq4jAhh+BqGj/GGrTDVtDs=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
  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.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
  This is the second paragraph. This is the second paragraph. This is the second
  paragraph. This is the second paragraph.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
</pre>
</div></div>
<h3 id="result">Result</h3>
<div class="section-content"><div class="code-example" id="sect2">

<iframe class="sample-code-frame" title="Examples sample" id="frame_examples" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/p/runner.html?id=examples" loading="lazy"></iframe>
</div></div>
<h2 id="styling_paragraphs">Styling paragraphs</h2>
<div class="section-content"><p>By default, browsers separate paragraphs with a single blank line. Alternate separation methods, such as first-line indentation, can be achieved with <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSS">CSS</a>:</p></div>
<h3 id="html_2">HTML</h3>
<div class="section-content"><div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="ArLnQg2kOLl8KSZ5VpaS6wrUF8m9ge4XH+7RP3M8tfg=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
  Separating paragraphs with blank lines is easiest for readers to scan, but
  they can also be separated by indenting their first lines. This is often used
  to take up less space, such as to save paper in print.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
  Writing that is intended to be edited, such as school papers and rough drafts,
  uses both blank lines and indentation for separation. In finished works,
  combining both is considered redundant and amateurish.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
  In very old writing, paragraphs were separated with a special character: ¶,
  the <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>i</span><span class="token punctuation">&gt;</span></span>pilcrow<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>i</span><span class="token punctuation">&gt;</span></span>. Nowadays, this is considered claustrophobic and hard to
  read.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
  How hard to read? See for yourself:
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">data-toggle-text</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Oh no! Switch back!<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    Use pilcrow for paragraphs
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
</pre>
</div></div>
<h3 id="css">CSS</h3>
<div class="section-content"><div class="code-example">
<p class="example-header"><span class="language-name">css</span></p>
<pre data-signature="vgpXjJe+JsfZeiUxmbRM7/M6B7zsSGiKQMxeZ+EhR/M=" data-language="css"><span class="token selector">p</span> <span class="token punctuation">{</span>
  <span class="token property">margin</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">text-indent</span><span class="token punctuation">:</span> 3ch<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">p.pilcrow</span> <span class="token punctuation">{</span>
  <span class="token property">text-indent</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> inline<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">p.pilcrow + p.pilcrow::before</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">" ¶ "</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre>
</div></div>
<h3 id="javascript">JavaScript</h3>
<div class="section-content"><div class="code-example">
<p class="example-header"><span class="language-name">js</span></p>
<pre data-signature="SD7N47Qi2DXpOUk8UvzrGUIfE0FpStuKBw4sSYFJIAk=" data-language="js">document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">"button"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">"click"</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">event</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  document<span class="token punctuation">.</span><span class="token function">querySelectorAll</span><span class="token punctuation">(</span><span class="token string">"p"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">paragraph</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    paragraph<span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">toggle</span><span class="token punctuation">(</span><span class="token string">"pilcrow"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token punctuation">[</span>event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>innerText<span class="token punctuation">,</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>dataset<span class="token punctuation">.</span>toggleText<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>
    event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>dataset<span class="token punctuation">.</span>toggleText<span class="token punctuation">,</span>
    event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>innerText<span class="token punctuation">,</span>
  <span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre>
</div></div>
<h3 id="result_2">Result</h3>
<div class="section-content"><div class="code-example" id="sect3">

<iframe class="sample-code-frame" title="Styling paragraphs sample" id="frame_styling_paragraphs" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/p/runner.html?id=styling_paragraphs" loading="lazy"></iframe>
</div></div>
<h2 id="accessibility_concerns">Accessibility concerns</h2>
<div class="section-content">
<p>Breaking up content into paragraphs helps make a page more accessible. Screen-readers and other assistive technology provide shortcuts to let their users skip to the next or previous paragraph, letting them skim content like how white space lets visual users skip around.</p> <p>Using empty <code>&lt;p&gt;</code> elements to add space between paragraphs is problematic for people who navigate with screen-reading technology. Screen readers may announce the paragraph's presence, but not any content contained within it — because there is none. This can confuse and frustrate the person using the screen reader.</p> <p>If extra space is desired, use <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSS">CSS</a> properties like <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin"><code>margin</code></a> to create the effect:</p> <div class="code-example">
<p class="example-header"><span class="language-name">css</span></p>
<pre data-signature="8IOLiGNqGIFy1pDARviiN2xl/VLbbo48fMURml9fhUk=" data-language="css"><span class="token selector">p</span> <span class="token punctuation">{</span>
  <span class="token property">margin-bottom</span><span class="token punctuation">:</span> 2em<span class="token punctuation">;</span> <span class="token comment">/* increase white space after a paragraph */</span>
<span class="token punctuation">}</span>
</pre>
</div>
</div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element">HTML Standard <br><small># the-p-element</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody><tr>
<th><code>p</code></th>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">15</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">14</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">1.0</td>
</tr></tbody>
</table></div>
<h2 id="see_also">See also</h2>
<div class="section-content"><ul> <li><a href="hr"><code>&lt;hr&gt;</code></a></li> <li><a href="br"><code>&lt;br&gt;</code></a></li> </ul></div><div class="_attribution">
  <p class="_attribution-p">
    &copy; 2005&ndash;2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
    <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p</a>
  </p>
</div>