Paragraphs and line breaks
What we will go through
- The <p> element
- Why extra spaces and Enter keys disappear
- When <br> is the right choice
- The <hr> thematic break
Short answer
Wrap each paragraph in <p> and </p>. Browsers collapse extra spaces and line breaks in your code into a single space, so pressing Enter does nothing on the page. Use <br> only when a line break is part of the content, like in an address or a poem. Use <hr> for a change of topic.
The paragraph element
<p>Our resort is 20 minutes from Tabaco port.</p>
<p>We have six rooms, a pool, and a view of Mayon.</p>
Each <p> becomes its own block with space above and below. Keep paragraphs short. On phones, two to four sentences reads best.
Whitespace collapse
<p>Hello
world</p>
This shows as Hello world with one space. HTML treats all runs of spaces, tabs, and line breaks as one space. This is called whitespace collapsing. It lets you indent code freely without changing the page.
Line breaks with <br>
<p>Mayon Bakeshop<br>
Rizal Street, Albay District<br>
Legazpi City, 4500</p>
Addresses, poems, and song lines need breaks inside one block. That is what <br> is for. Do not stack <br><br> to make space between paragraphs. Use separate <p> elements and CSS spacing.
Thematic break with <hr>
<hr> marks a shift in topic, like a scene change. Browsers draw it as a horizontal line. It is a void element, so it has no closing tag. For <pre>, which keeps spaces exactly as typed, see the code examples in this course.
Try it: format an address
The address below runs onto one line. Add br tags so each part sits on its own line, and split the description into two paragraphs.
Live preview
Quick quiz
Common mistakes
- Stacking br tags for spacing. It creates messy, inaccessible spacing. Use CSS margin.
- One huge paragraph. Long blocks are hard to read on phones.
- Expecting Enter to work. Line breaks in code do not appear on the page.
Your action
Tick each item when you can do it. Your progress saves on this device.
Key terms
- <p>
- The paragraph element.
- Whitespace collapsing
- Browsers merging runs of spaces into one.
- <br>
- A line break inside a block of text.
- <hr>
- A thematic break between topics.
- <pre>
- Preformatted text that keeps spaces as typed.
Questions beginners ask
Is <br> bad?
No, it is fine for real line breaks. It is only bad when used for layout.
Can I put a heading inside a p?
No. Headings and paragraphs are separate blocks.
How do I add a non-breaking space?
Use to keep two words together, like ₱ 500.
Related lessons
Need a website built or fixed while you practice? The team at Remar Digital can help.