diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/html/element%2Fp.html | |
new repository
Diffstat (limited to 'devdocs/html/element%2Fp.html')
| -rw-r--r-- | devdocs/html/element%2Fp.html | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/devdocs/html/element%2Fp.html b/devdocs/html/element%2Fp.html new file mode 100644 index 00000000..5abe191c --- /dev/null +++ b/devdocs/html/element%2Fp.html @@ -0,0 +1,163 @@ +<header><h1><p>: The Paragraph element</h1></header><div class="section-content"> +<p>The <code><p></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></p></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><p></code></a> element is immediately followed by an <a href="address"><code><address></code></a>, <a href="article"><code><article></code></a>, <a href="aside"><code><aside></code></a>, <a href="blockquote"><code><blockquote></code></a>, <a href="details"><code><details></code></a>, <a href="div"><code><div></code></a>, <a href="dl"><code><dl></code></a>, <a href="fieldset"><code><fieldset></code></a>, <a href="figcaption"><code><figcaption></code></a>, <a href="figure"><code><figure></code></a>, <a href="footer"><code><footer></code></a>, <a href="form"><code><form></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><header></code></a>, <a href="hgroup"><code><hgroup></code></a>, <a href="hr"><code><hr></code></a>, <a href="main"><code><main></code></a>, <a href="menu"><code><menu></code></a>, <a href="nav"><code><nav></code></a>, <a href="ol"><code><ol></code></a>, <a href="pre"><code><pre></code></a>, <a href="search"><code><search></code></a>, <a href="section"><code><section></code></a>, <a href="table"><code><table></code></a>, <a href="ul"><code><ul></code></a> or another <a href="p" aria-current="page"><code><p></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><a></code></a>, <a href="audio"><code><audio></code></a>, <a href="del"><code><del></code></a>, <a href="ins"><code><ins></code></a>, <a href="map"><code><map></code></a>, <a href="noscript"><code><noscript></code></a> or <a href="video"><code><video></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><p></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"><</span>p</span><span class="token punctuation">></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"></</span>p</span><span class="token punctuation">></span></span> +<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></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"></</span>p</span><span class="token punctuation">></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"><</span>p</span><span class="token punctuation">></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"></</span>p</span><span class="token punctuation">></span></span> + +<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></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"></</span>p</span><span class="token punctuation">></span></span> + +<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></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"><</span>i</span><span class="token punctuation">></span></span>pilcrow<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>i</span><span class="token punctuation">></span></span>. Nowadays, this is considered claustrophobic and hard to + read. +<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span> + +<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></span></span> + How hard to read? See for yourself: + <span class="token tag"><span class="token tag"><span class="token punctuation"><</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">></span></span> + Use pilcrow for paragraphs + <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>button</span><span class="token punctuation">></span></span> +<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></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">=></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">=></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><p></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><hr></code></a></li> <li><a href="br"><code><br></code></a></li> </ul></div><div class="_attribution"> + <p class="_attribution-p"> + © 2005–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> |
