HTML p Tag - Learn HTML | W3Docs (2024)

❮ Prev Next ❯

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.

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.

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 .

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

Example of the HTML <p> tag:

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

Try it Yourself »

Result

HTML p Tag - Learn HTML | W3Docs (1)

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:

<!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>

Try it Yourself »

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

<!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>

Try it Yourself »

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 signalled 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:

  • CSS text-shadow property adds shadow to text.
  • CSS text-align-last property sets the alignment of the last line of the text.
  • CSS line-height property specifies the height of a line.
  • CSS letter-spacing property defines the spaces between letters/characters in a text.
  • CSS word-spacing property sets the spacing between words.

Browser support

HTML p Tag - Learn HTML | W3Docs (2) HTML p Tag - Learn HTML | W3Docs (3) HTML p Tag - Learn HTML | W3Docs (4) HTML p Tag - Learn HTML | W3Docs (5) HTML p Tag - Learn HTML | W3Docs (6)

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

HTML p Tag - Learn HTML | W3Docs (7)

Correct!

HTML p Tag - Learn HTML | W3Docs (8)

Incorrect!

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

  • HTML Basics

❮ Prev Next ❯

  • How to Make Button onclick in HTML
  • How to Set Background Color with HTML and CSS
  • How to Add Border to HTML Table
  • How to Add a Blur Filter to the Background Image
  • How to Disable Zoom on a Mobile Web Page With HTML and CSS
  • How to Override CSS Styles
  • How to Create Stacked Paper Effect
  • How to Create a Fixed Navbar with CSS
  • How to Give a Div Element 100% Height of the Browser Window
  • How to Create Drop Caps for the Text
  • How to Create a Shining Text Animation Effect
  • How to Increase the Space Between Text and Underlining in CSS
  • How to Import Google Fonts in CSS File
  • How to Make a Div Stick to the Top of Screen when Scrolling with CSS and Javascript
  • How to Stretch a Text with CSS
  • How to Apply Global Font to the Entire HTML Document
  • How to Add Style to the Parent Element when Hovering a Child Element
  • How to Add Line Break Before an Element with CSS
  • How to Make Scrollbar Visible Only when Necessary
  • How to Prevent Scrollbar from Repositioning Web Page
  • How to Get a Specific Number of Child Elements With CSS
  • How to Truncate Multi-Line String with Pure CSS
  • How to Break Line Without Using <br> Tag in CSS
  • How to Select All Child Elements Recursively in CSS
  • How to Make a <div> Fill the Height of the Remaining Space
  • How to Create an Unordered List without Bullets
  • How to Change the Color of an <hr> Element
  • How to Create a Hidden Div without a Line Break or Horizontal Space
  • How to Right Align a Button with CSS
  • How to Add a Mouseover Text with HTML
  • How to Select the Last Element of a Specific Type
  • How Not to Wrap the Contents of <p>, <div>, and <span> Elements
  • How to Vertically Center Inline (Inline-Block) Elements
  • How to Select the Last Second Element with CSS
  • How to Horizontally Center Contents Within a Div
  • How to Hide Elements in a Responsive Layout
  • What does the CSS Tilde (~) Selector Mean
  • How to Select the Next Element in CSS

Sorry about that

Thanks for your feedback!

Thanks for your feedback!

Do you find this helpful?

HTML p Tag - Learn HTML | W3Docs (2024)

References

Top Articles
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 5334

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.