1. html
  2. /tags
  3. /p

<p>

Overview

The <p> element defines a paragraph in HTML, functioning as a structural block that encapsulates content. In visual media, it often manifests as blocks of text visually separated by blank lines. However, in HTML, a paragraph can encapsulate more than just textual content, including images, form fields, or any related group of content.

Examples and Usage

In HTML, the <p> element predominantly serves as a container for textual content. By default, due to its block-level nature, browsers render paragraphs as distinct blocks, separated by vertical margins.

<p>HTML is the standard markup language for documents designed to be displayed in a web browser.</p>
<p>Cascading Style Sheets (CSS) is a stylesheet language used for describing the look and formatting of a document written in HTML.</p>

While the default browser settings provide a distinct separation between paragraphs, CSS allows for finer control over their appearance. For instance, if we want to introduce a text indentation to the first line of a paragraph or to adjust the vertical spacing between paragraphs, we can use the following styles:

<p style="text-indent: 2em;">HTML provides the structure of a web page, dictating how content is organized and displayed.</p>
<p style="margin-top: 2em;">In partnership with CSS, HTML ensures that web content is both structured and visually appealing.</p>

For more extensive styling and to maintain cleaner code, these styles would commonly be applied via a separate linked stylesheet.

Despite its block-level nature, the <p> element can also be styled to display inline with other elements, though this isn't a frequent use-case.

Regarding tag omission, the opening <p> tag is always required. The closing </p> tag can occasionally be omitted, especially when succeeded by another block-level element. However, for clarity and consistency, it's generally recommended to include both tags. More on this can be found in the Associated Elements section below.

Attribute Breakdown

The <p> element doesn't have any specific attributes; it uses the global attributes applicable to all HTML elements.

Accessibility Aspects

Structuring content into paragraphs aids in making web content more accessible. For users leveraging screen readers and other assistive technologies, paragraphs provide natural breakpoints, allowing for more straightforward navigation.

However, using empty <p> elements for spacing can be problematic. Such empty elements might be announced by screen readers but without conveying any meaningful content, potentially confusing the user. Instead of relying on empty paragraphs for layout purposes, it's advisable to utilize CSS for spacing and layout control.

Associated Elements

  • <br>
  • <hr>

Note: The end tag of the <p> element can be omitted if it is immediately followed by block-level elements like <address>, <article>, <div>, <section>, and others, another <p> element, or if no more content is present in its parent element, provided the parent isn't an <a> element.

Additional Notes

  • In HTML, paragraphs have a unique relationship with other block-level elements. Specifically, if a block-level element starts before a closing </p> tag, browsers will automatically conclude the open <p> element. This behavior aids in maintaining the structural integrity of the content.

  • Semantically, using specific elements like <footer> or <address> is preferable when they align better with the content's context than a generic paragraph. For instance, marking up author information with an <address> tag within an <article> or <section> provides clearer semantic meaning than merely using a <p> tag.

  • When building dynamic websites, the <p> element often serves as a target for JavaScript-based manipulations. Due to its common usage as a text container, developers frequently update, hide, or modify paragraph content in response to user interactions or other events on the webpage. So, a <p> element might be updated to display a user's input, show error messages, or provide real-time feedback.

Browser Compatibility

For a detailed breakdown of specific browser nuances and older version support refer to the first link in the Useful Resources below.

BrowserChromeEdgeSafariFirefoxOperaInternet Explorer
SupportYesYes*YesYesYesYes*

Useful Resources

Can I use HTML element: p

The HTML Living Standard Specification: p