HTML <p> tag
The <p> tag is used to define an HTML paragraph. This tag allows to write a bundle of sentences or descriptions.
It is block level element so that the web-browser leaves some spaces before and after the <p> element. But it can be changed customly by using CSS margin property.
Type: Block Element
Syntax of <p> tag
<p> This is a paragraph. </p>
Full code example
<!DOCTYPE html> <html> <head> </head> <body> <h2>Heading Name</h2> <p> Heading description </p> <h2>Another Heading</h2> <p> Another description </p> </body> </html>
If you are absolutely beginner to HTML5, it is recommended to use <p> tag to write sentences.
Supported Browsers
| Tag | Chrome | Internet Explorer | Firefox | Safari | Opera Mini |
|---|---|---|---|---|---|
| <p> | Yes | Yes | Yes | Yes | Yes |
Attributes of <p> tag
| Attribute | Value | Note |
|---|---|---|
| align | left right center justify |
It defines the alignment of the paragraph. |
align attribute is obsolete in HTML5 and it is completely replaced by CSS.
Use of align attribute (Obsolete)
<p align="left"> Left-aligned paragraph. </p> <p align="right"> Right-aligned paragraph. </p> <p align="center"> Centered-aligned paragraph. </p> <p align="justify"> This paragraph preserves both ends equally in length. To show this, we have to write some sentence. Actually, HTML5 was designed to replace HTML 4.01, XHTML, and the HTML DOM Level 2. HTML5 is the latest version which is now currently used by all the web developers. HTML5 has more advantages than the HTML 4.0.1. Beyond just formatting, HTML5 describes the contents of a web page so that both humans and computers can read it. </p>
Example of CSS replacement
<p style="text-align: left;"> Left-aligned paragraph. </p> <p style="text-align: right;"> Right-aligned paragraph. </p> <p style="text-align: center;"> Centered-aligned paragraph. </p> <p style="text-align: justify;"> This paragraph preserves both ends equally in length. To show this, we have to write some sentence. Actually, HTML5 was designed to replace HTML 4.01, XHTML, and the HTML DOM Level 2. HTML5 is the latest version which is now currently used by all the web developers. HTML5 has more advantages than the HTML 4.0.1. Beyond just formatting, HTML5 describes the contents of a web page so that both humans and computers can read it. </p>
Output on the browser
Left-aligned paragraph.
Right-aligned paragraph.
Centered-aligned paragraph.
This paragraph preserves both ends equally in length. To show this, we have to write some sentence. Actually, HTML5 was designed to replace HTML 4.01, XHTML, and the HTML DOM Level 2. HTML5 is the latest version which is now currently used by all the web developers. HTML5 has more advantages than the HTML 4.0.1. Beyond just formatting, HTML5 describes the contents of a web page so that both humans and computers can read it.
Default CSS properties of <p> tag
p { display:block; margin:1em auto; text-align:left; }
More reference
It is a common mistake that putting another HTML block-level elements like (<div>, <table> or <aside>) inside the <p> tag. You know that paragraphs are written within <p> and </p> tags. The end tag (</p>) can be omitted when another block-level element follows.
<p> A paragraph <div> --Contents-- </div>
