Adding a line break is a common need when designing web content — whether it’s to improve readability, space elements clearly, or create structured layouts. While HTML provides the <br>
tag for line breaks, CSS can also help you control when and how line breaks occur.
In this blog post, we’ll walk through various CSS techniques to add or control line breaks, along with practical examples.
✅ 1. Use HTML <br>
for Manual Line Breaks
While this isn’t CSS, it’s important to understand that the <br>
tag is the standard way to manually insert a line break in HTML:
<p>This is line one.<br>This is line two.</p>
However, CSS gives you more flexible, automatic control over line breaks.
✅ 2. Force a Line Break Using CSS display
Property
If you want to insert a break between two inline elements:
✅ Example:
<span class="block-item">First Line</span>
<span class="block-item">Second Line</span>
.block-item {
display: block;
}
✔️ display: block;
forces each element to appear on a new line.
✅ 3. Add Line Break After or Before an Element Using ::after
or ::before
✅ CSS Example:
<p class="add-break">Hello</p>
.add-break::after {
content: "";
display: block;
}
✔️ This CSS adds a virtual line break after the element.
✅ 4. Use white-space
to Control Line Breaking Behavior
.breakable {
white-space: normal;
}
.no-break {
white-space: nowrap;
}
✅ Example:
<div class="no-break">This sentence will stay in one long line.</div>
<div class="breakable">This sentence will wrap naturally when needed.</div>
✔️ white-space: nowrap
prevents line breaks, while normal
allows them.
✅ 5. Control Word Wrapping with word-break
and overflow-wrap
When dealing with long words or URLs, use:
.long-word {
word-break: break-word;
overflow-wrap: break-word;
}
This ensures words break onto the next line when they exceed container width.
✅ 6. Use margin
or padding
for Visual Line Breaks (Spacing)
You can simulate line breaks by adding vertical spacing between block elements:
.divider {
margin-bottom: 20px;
}
🧠 Summary Table
Task | CSS Property | Description |
---|---|---|
Force new line | display: block | Makes inline elements break line |
Insert break after element | ::after { display: block; } | Adds line break using pseudo-element |
Prevent/allow wrapping | white-space | Controls inline element line wrapping |
Break long words/URLs | word-break , overflow-wrap | Manages how words wrap inside container |
Visual spacing | margin-bottom | Adds spacing similar to a break |
🔚 Conclusion
While HTML’s <br>
tag works for manual line breaks, CSS offers more flexible, dynamic, and maintainable solutions. From forcing breaks between elements to controlling how text wraps, mastering these CSS properties helps create cleaner, more professional layouts.