Skip to main content

HTML Basics

HTML Paragraphs

Written by Updated HTML Paragraphs exercises

A paragraph in HTML is text inside p tags. The browser gives each one space above and below. What surprises beginners is the other rule: pressing Enter or typing extra spaces in your code changes nothing on the page.

What Is an HTML Paragraph?

A paragraph is written with the <p> element. Each one is its own block of text, with a gap before and after it.

Paragraph Example

html

<p>This is my first paragraph.</p>
<p>This is another paragraph with more text.</p>

The two paragraphs appear one below the other with space between them.

How Browsers Handle Paragraphs

Example

html

<p>This
is     one
paragraph.</p>

On the page, this shows as "This is one paragraph." on a single line. HTML collapses every run of spaces and line breaks into one space. For a line break inside a paragraph, use the br tag; to keep spacing exactly as typed, use the pre tag.

Paragraph Styling with CSS

Example

html

<p style="color: #29AB87; font-size: 18px; line-height: 1.6;">
HTML paragraphs make your text organized and easy to read.
</p>

The text becomes green, 18px, with more space between lines. In a real site, put these rules in a stylesheet instead of the style attribute, so every paragraph shares them.

Aligning Text in Paragraphs

Example

html

<p style="text-align:center;">This paragraph is centered.</p>
<p style="text-align:right;">This paragraph is aligned to the right.</p>
<p style="text-align:justify;">This paragraph is justified like in newspapers.</p>

Nested Elements Inside Paragraphs

Inline elements such as <strong>, <em> and <a> can go inside a paragraph:

Example

html

<p>HTML <strong>paragraphs</strong> can include <em>formatted text</em> and <a href="#">links</a>.</p>

Things to remember

  • A paragraph cannot contain block-level elements such as <div>, <ul> or headings. If you put one inside, the browser closes the paragraph early.
  • Do not use empty paragraphs or <br><br> for spacing. Change the margin in CSS.
  • Long lines are hard to read. Keep paragraph text to about 60 to 75 characters wide, for example with max-width: 65ch.
  • Every paragraph needs a closing </p>. Browsers often guess correctly without it, but not always.

The tag itself is covered in the p tag.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

HTML Paragraphs exercises

Three paragraphs

Write three paragraphs, one for each sentence: One idea. Next idea. Last idea.

Result

Check your answer to see it here.