Advertisement
❮ Previous: HTML Headings Next: HTML Styles ❯

HTML Paragraphs

The HTML <p> element defines a paragraph.

A paragraph always starts on a new line, and browsers automatically add some white space (a margin) before and after a paragraph.

The <p> tag offers a way to structure your text into different paragraphs. Each paragraph of text should go in between an opening <p> and a closing </p> tag as shown below in the example:

Example

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

Try this code ❯

<p> block element is used to define a paragraph of text.

<p> is a block element, browsers typically insert a blank line, but this rendering should not be assumed, given the rise of style sheets, which can use the display property to override this action.

Under the strict (X)HTML and HTML5 specifications, the align attribute is not supported. Alignment of text can instead be accomplished using CSS properties like text-align.

The closing tag for the <p> tag is optional under the HTML specification but not recommended; however, under the XHTML 1.0 specification, the closing tag </p> is required for XHTML compatibility.

Empty paragraphs are ignored by browsers.

Note: To create blank lines use the <br>element.


Advertisement

More Examples

Add CSS to <p> element

Example

<p  style="text-align:right">This is a paragraph.</p>
<p>This is another paragraph.</p>

Try this code ❯


How to display proper poem:

Example

<p>He who knows not, <br>
and knows not that he knows not,<br>
is a fool; shun him.<br>
<br>
He who knows not,<br>
and knows that he knows not, <br>
is a student; Teach him.<br>
<br>
He who knows,<br>
and knows not that he knows,<br>
is asleep; Wake him.<br>
<br>
He who knows,<br>
and knows that he knows,<br>
is Wise; Follow him.</p>

Try this code ❯


How to add line breaks

Example

<p>This is <br> a paragraph.</p>

Try this code ❯

Read more about <br> tag


How to add horizontal rules

Example

<p>This is a paragraph.</p>
<hr>
<p>This is another paragraph.</p>

Try this code ❯

Read more about <hr> tag


How to make preformatted text

Example

<pre>He who knows not,
and knows not that he knows not,
is a fool; shun him.

He who knows not,
and knows that he knows not,
is a student; Teach him.

He who knows,
and knows not that he knows,
is asleep; Wake him.

He who knows,
and knows that he knows,
is Wise; Follow him.</pre>

Try this code ❯

Read more about <pre> tag


A complete list of all HTML tags, see HTML Tag Reference.

❮ Previous: HTML Headings Next: HTML Styles ❯
Advertisement