Web Development - HTML Paragraphs
HTML Paragraphs
Paragraphs are used to display blocks of text on a web page.
In HTML, paragraphs are defined with the <p> element:
Browsers automatically add space before and after each paragraph. You don't need to add extra line breaks manually.
Multiple Paragraphs
You can add as many paragraphs as you want. Each one will start on a new line automatically:
Example
Multiple paragraphs:
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>And this is the third paragraph.</p>
Try it Yourself »
Tip: Always enclose your text inside a paragraph tag. It helps browsers display text consistently and improves accessibility.
HTML Line Breaks
Like we mentioned in a previous chapter, if you want text to start on a new line without starting a new paragraph, use the <br> element:
Example
Using line breaks:
<p>This is the first line.<br>This is the second line.</p>
Try it Yourself »
The <br> tag is an empty element - it does not have a closing tag.
Horizontal Lines
The <hr> element defines a thematic break in the page (for example, between sections).
Example
Using a horizontal rule:
<h2>Chapter 1</h2>
<p>This is the first chapter.</p>
<hr>
<h2>Chapter 2</h2>
<p>This is the second chapter.</p>
Try it Yourself »
The <hr> tag is also an empty element and is commonly used to separate content visually.
Preformatted Text
The <pre> element displays text exactly as it is written in the HTML source, including spaces and line breaks:
Example
Using the <pre> tag:
<pre>
This text will keep
its spaces and
line breaks!
</pre>
Try it Yourself »
Summary
- Use
<p>for paragraphs of text. - Use
<br>to insert line breaks inside a paragraph. - Use
<hr>to create horizontal lines. - Use
<pre>if you need to preserve spacing exactly.
Next, you'll learn about HTML Formatting - how to make text bold, italic, underlined, and more.