HTML <p> Tag

The <p> tag defines a paragraph of text. It is a block-level element, it always start on a new line, and browsers automatically add margin before and after each paragraph. You can modify the margins using CSS margin property .

If you need to just to move text to a new line use the <br> tag.

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 .

Syntax

Paragraphs are written between the opening (<p>) and the 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.

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

Example

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

Result

Using the CSS

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

Example
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div.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>

Result

Attributes

Attribute Value Description
align right
left
justify
Defines the text alignment.
Not supported in HTML5

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

How to style <p> tag

Common properties to alter the visual weight/emphasis/size of text in <p> tag:?

  • CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit
  • CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
  • CSS font-size property sets the size of the font.
  • CSS font-weight property defines whether the font should be bold or thick. CSS text-transform Property controls text case and capitalization.
  • CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style

Coloring text in <p> tag:

  • CSS color property describes the color of the text content and text decorations
  • CSS background-color property sets the background color of an element.

Text layout styles for <p> tag:

  • CSS text-indent property specifies the indentation of the first line in a text block.
  • CSS text-overflow property specifies how overflowed content that is not displayed should be signaled to the user.
  • CSS white-space property specifies how white-space inside an element is handled.
  • CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <p> tag


Browser support



Do you find this helpful?

Related articles