HTML Paragraph p tag
HTML Paragraph p tag is used to give structure to the text content placed inside the body tag. According to W3C it is not recommended to use open white space to write text content inside it. W3C recommends using the HTML paragraph p tag element to develop a readable structure as well as valid HTML structured document. By default the text placed inside the <p> tag of HTML is displayed as left aligned by web browsers. Paragraph <p> HTML tag is rendered with blank line above the paragraph and single blank line space below the paragraph. Spacing above and below the paragraph depends on the DTD understanding of the different web browsers.
You can see the live samples and examples of HTML Basic tags from the following links:
Paragraph <p> tag attributes
The HTML p tag also supports 2 types of attributes:
align: align attributes accepts values as left, right, center or justify. Each value adjusts the paragraph text or you can say whole paragraph alignment according to the value of align attribute.
style: style attribute helps in applying inline style to the paragraph text.
Paragraph p tag Example with align attribute
<p> Paragraph p tag example without align attribute. It rendered the paragraph left aligned by default. </p> <p align="left"> Second example of paragraph p tag with align attribute value as left. Paragraph appeared same as default p tag in the above example. </p> <p align="center"> Third example of paragraph p tag with align attribute value as center. Paragraph is aligned center on the HTML web page. </p> <p align="right"> This time paragraph is displayed as right aligned along with text as right aligned. Right aligned paragraph text is rarely used. </p> <p align="justify"> Paragraph p tag with align attribute value as justify. Old browsers do not support this value of align attribute. </p>
Do not use blank paragraph tags inside the paragraph p tags to enter the line breaks between two lines. This will lead to invalid HTML. In HTML <br /> tag is used to insert the line break between two sentences. When you write text inside the HTML p tag and uses ENTER key of Keyboard to insert line break between two sentences, it does not work for example:
<p> Line 1 of paragraph Line 2 of paragraph Line 3 of paragraph </p>
Above HTML code will display the text in a single line as below:
Line 1 of paragraph Line 2 of paragraph Line 3 of paragraph
So you have to use line break <br> or <br /> HTML tag to insert the line break or blank line between two lines.
HTML Line Break <br> Tag example
<p> Line 1 of paragraph<br /> Line 2 of paragraph<br> Line 3 of paragraph<br /> </p>
Actually there is no difference in <br> and <br /> tag. According to new rules of XHTML of W3C each tag should be closed properly.
Above line break <br> tag example will show each line in new line of browser:
Line 1 of paragraph
Line 2 of paragraph
Line 3 of paragraph
Continue to next tutorial: HTML Blockquote and Quote Tag to learn quoted HTML text formatting tags.