How to use the HTML <p> Element

Learn how to use the HTML <p> (paragraph) element.

The HTML (<p>) element is used to define paragraph elements:

<p>Here is some text inside a paragraph element.</p>

The <p> element is by far the most used text element on the web. This article you’re reading almost exclusively consists of paragraph elements.

The <p> element is a block-level element. This means that by default, every defined paragraph in your document will take up a new line in the browser:

<p>Here is some text inside a paragraph element.</p>

<p>Here is another text inside another paragraph element.</p>

If you swapped out the <p> tags with <span> tags, those two text blocks would display inline (right next to each other, instead of being stacked) because <span> is an inline element.

By default, paragraph elements inherit the following styling properties from the User-Agent Stylesheet (in most browsers):

p {
  display: block;
  margin-top: 1em;
  margin-bottom: 1em;
  margin-left: 0;
  margin-right: 0;
}

This enforces a clear line separation by applying top and bottom white space with the margin property.

You can of course always override those styles by importing a CSS style sheet (or with inline styles).


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on