CSS
CSS: How to Break a Line (Line Breaks in Web Design)
When designing a webpage, you’ll often want to control where and how text breaks onto a new line. Whether you’re formatting paragraphs, headings, or inline content, CSS provides several ways to manage line breaks for better readability and responsive layouts.
In this blog post, you’ll learn:
- ✅ How to insert manual line breaks using HTML
- ✅ How to force or prevent line breaks with CSS
- 🧪 Practical examples for layout and formatting
- 🧠 Tips for controlling text wrapping and spacing
✅ 1. Manual Line Break with <br>
(HTML)
The simplest way to break a line manually is to use the <br>
tag.
✅ Example:
<p>This is the first line.<br>This is the second line.</p>
🟢 Use this when you want a new line without starting a new paragraph.
✅ 2. Use CSS to Break Lines Automatically (Word Wrapping)
CSS gives you control over how text wraps in a container.
🧪 Example 1: Wrapping long words
.break-word {
word-wrap: break-word; /* older syntax */
overflow-wrap: break-word; /* modern syntax */
}
✅ HTML:
<div class="break-word">
ThisIsAnExtremelyLongWordThatWillBreakIntoNewLineAutomaticallyIfNeeded.
</div>
✅ Useful when dealing with long URLs or unbroken strings.
✅ 3. Force a Line Break with display: block
or inline-block
If you want elements like <span>
or <a>
to break into a new line:
✅ Example:
.line-break {
display: block;
}
<span class="line-break">Line One</span>
<span class="line-break">Line Two</span>
✅ This forces each element to appear on its own line.
✅ 4. Prevent Line Breaks with white-space: nowrap
Want to keep everything on one line even if it overflows?
✅ CSS:
.no-break {
white-space: nowrap;
}
✅ HTML:
<div class="no-break">
This content will not wrap onto the next line.
</div>
✅ Useful for buttons, tags, navigation, etc.
✅ 5. Line Breaks in Headings or Buttons
For aesthetic formatting, you might want to break lines within headings:
✅ HTML:
<h1>Welcome to<br>My Website</h1>
📌 Don’t overuse <br>
for layout—prefer CSS for consistent spacing.
🧠 Summary
Goal | Use This |
---|---|
Manual line break | <br> |
Wrap long words automatically | overflow-wrap: break-word |
Force line break between elements | display: block |
Prevent line breaks | white-space: nowrap |
Break lines aesthetically (headings) | <br> or styled <span> s |
🏁 Final Thoughts
Breaking lines in CSS is about more than just appearance—it’s about readability, accessibility, and responsive design. Use HTML <br>
sparingly and rely on CSS for layout and wrapping control.
Whether you need to break long words, wrap text elegantly, or prevent unwanted breaks, CSS has all the tools you need.