HTML Paragraphs

Learn how to structure text content in HTML using paragraphs.

On this page

HTML Paragraphs

A paragraph always starts on a new line and is usually a block of text.

The HTML <p> element defines a paragraph. Browsers automatically add space before and after paragraphs.


Example

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

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


HTML Display

You cannot be sure how HTML will be displayed. Screen size and window resizing can change the result.

Extra spaces and line breaks in HTML source code are ignored by the browser.


Example

<p>

This paragraph

contains a lot of lines

in the source code,

but the browser

ignores it.

</p>


<p>

This paragraph

contains     a lot of spaces

in the source     code,

but the    browser

ignores it.

</p>


HTML Horizontal Rules

The <hr> tag defines a thematic break in an HTML page and is usually displayed as a horizontal line.

The <hr> element is an empty tag and has no closing tag.


Example

<h1>This is heading 1</h1>

<p>This is some text.</p>

<hr>

<h2>This is heading 2</h2>

<p>This is some other text.</p>

<hr>


HTML Line Breaks

The <br> element defines a line break without starting a new paragraph.

The <br> tag is an empty tag and has no closing tag.


Example

<p>This is<br>a paragraph<br>with line breaks.</p>


The Poem Problem

Line breaks and spacing inside a paragraph are ignored by the browser.


Example

<p>

 My Bonnie lies over the ocean.


 My Bonnie lies over the sea.


 My Bonnie lies over the ocean.


 Oh, bring back my Bonnie to me.

</p>


Solution: The HTML <pre> Element

The <pre> element preserves spaces and line breaks and displays text in a fixed-width font.


Example

<pre>

 My Bonnie lies over the ocean.


 My Bonnie lies over the sea.


 My Bonnie lies over the ocean.


 Oh, bring back my Bonnie to me.

</pre>


HTML Paragraphs Examples (7)