Skip to main content

HTML Tags

HTML <p> Tag

Written by Updated HTML <p> Tag exercises

The p tag marks a paragraph. It is the most common tag in any article, and it has one surprise for beginners: pressing Enter in your code does not create a new line on the page.

Syntax

html

<p>This is a paragraph of text.</p>

It has no special attributes, only the global ones such as class, id, style and title.

Example

html

<p>This is the first paragraph on the page.</p>
<p>This is the second paragraph, which is separated from the first by default spacing.</p>

Each paragraph appears on its own line with a gap above and below it. That gap is a default margin added by the browser, not empty lines in your code.

Why my line breaks disappear

HTML treats every run of spaces, tabs and line breaks as a single space. So this:

Line breaks in the code are ignored

html

<p>Roses are red,
   violets are blue.</p>

shows as one line: "Roses are red, violets are blue." To start a new paragraph, close the p and open a new one. For a line break inside one paragraph, like in a poem or an address, use the br tag. To keep spacing exactly as typed, use the pre tag.

Changing the gap between paragraphs

Do not add empty paragraphs or several <br> tags to create space. Change the margin in CSS instead:

Control paragraph spacing

css

p {
  margin: 0 0 1em;
  line-height: 1.6;
}

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Rules that catch people out

  • No blocks inside a paragraph. Paragraphs are block-level elements, and they cannot contain other blocks such as <div>, <ul> or headings. If you write <p><div>...</div></p>, the browser closes the paragraph before the div, and your CSS stops matching.
  • Do not use p for spacing. An empty <p></p> is read out by some screen readers as a blank paragraph.
  • Use headings for headings. Bold text in a <p> looks like a heading but search engines and screen readers do not treat it as one.

HTML <p> Tag exercises

Write a paragraph

Write one paragraph: Web pages are built from elements.

Result

Check your answer to see it here.