Skip to content

HTML <p> Tag

The HTML <p> tag is a block-level element that is used to define a paragraph of text in a web page. It creates a new line before and after the element, taking up the full width of its parent container.

This semantic tag is commonly used to structure text content on a web page, such as articles, blog posts, or product descriptions. You can add other HTML tags, such as <strong> or <em>, within the <p> tag to add emphasis or formatting to specific words or phrases within the paragraph.

Properly structuring your text content with the <p> tag is important, as it can help improve the accessibility and usability of your web page. Screen readers and other assistive technologies rely on semantic tags like <p> to accurately interpret and present the content to users.

Syntax

The <p> tag comes in pairs. The content is written between the opening (<p>) and closing (</p>) tags. If the closing tag is omitted, it is considered that the end of the paragraph matches with the start of the next block-level element.

TIP

Spaces between the opening <p> tag and its content are ignored by the browser. In order to set an indent, use the CSS text-indent property .

DANGER

The <p> tag cannot contain tables and other block-level elements.

Example of the HTML <p> tag:

Example of the HTML <p> Tag

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <p>This is a paragraph</p>
  </body>
</html>

Result

paragraph example

Using the CSS

To align a text in a paragraph, instead of the obsolete align attribute, use the CSS text-align property.

Example of the HTML <p> tag used with the CSS text-align property:

HTML <p> Tag with the CSS text-align property

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .paragraph {
        text-align: center;
      }
    </style>
  </head>
  <body>
    <h1>Title of the document</h1>
    <div class="paragraph">
      <p>The text alignment to the center is set with CSS property text-align</p>
    </div>
  </body>
</html>

Example of the HTML <p> tag used with the <br> tag:

Example of the HTML <p> tag with the HTML <br> tag:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <p> Inside the paragraph, we can put the tag &lt;br /&gt;, <br /> to transfer a part of the text to another line if necessary.</p>
    <p>Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. <br /> The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
  </body>
</html>

Attributes

AttributeValueDescription
alignright left justifyDefines the text alignment. Not supported in HTML5

The <p> tag also supports the Global Attributes and the Event Attributes.

How to style an HTML <p> Tag

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p {
        color: blue;
        font-size: 18px;
        text-align: justify;
      }
    </style>
  </head>
  <body>
    <p>This paragraph is styled with CSS.</p>
  </body>
</html>

Practice

What is the purpose of the HTML <p> tag?

Dual-run preview — compare with live Symfony routes.