Key points
- A word without spaces never breaks by default:
overflow-wrap: anywherelets it break, but only when it has to. - Inside a Flexbox or Grid container, add
min-width: 0(orminmax(0, 1fr)), otherwise the item refuses to shrink. hyphens: autogives clean, hyphenated breaks, provided the page’slangattribute is right.
An email address poking out of its card, a URL pasted into a blog post pushing the page sideways, a column that widens as soon as a product name gets a bit long: on mobile, these overflows cause horizontal scrolling that instantly makes a site look broken. We fix them regularly during acceptance testing, because they only show up with real content, never with the placeholder text in mock-ups. The fix is a few lines of CSS, as long as you pick the right property and know about the Flexbox trap.
Why text overflows
The browser only breaks a line at “break opportunities”: spaces, hyphens, some punctuation. A URL, an email address, an order reference or a long compound word has none. If that run of characters is wider than its container, it simply sticks out.
On a desktop, the column is often wide enough that nobody notices. On a phone, the same URL overflows, the page becomes wider than the screen and the user can drag it sideways. If you can’t tell which element is responsible, our article on horizontal scrolling on mobile explains how to find it in the developer tools.
overflow-wrap or word-break: picking the right property
There are two families of properties, and they don’t do the same job:
overflow-wrap: break-wordandoverflow-wrap: anywherebreak a word only if it doesn’t fit on the line. Normal text is left alone;word-break: break-allbreaks anywhere, all the time, even in the middle of words that would fit on the next line. Unreadable for a paragraph, but right for a technical string with no linguistic meaning.
/* Text may break anywhere, but only when nothing else fits */
.card {
overflow-wrap: anywhere;
}
/* For an ID, a hash or an API key: break strictly anywhere */
.api-key {
font-family: ui-monospace, monospace;
word-break: break-all;
}
The difference between break-word and anywhere is subtle but matters. With anywhere, the possible breaks count when the browser works out the element’s minimum width; with break-word, they don’t. In practice, in a table cell, a flex item or a box sized with min-content, break-word often lets the text overflow while anywhere breaks it. That’s why anywhere is our default; every current browser supports it.
You’ll also come across word-break: break-word in older CSS. It’s deprecated and behaves like overflow-wrap: anywhere, which you’re better off writing directly.
The Flexbox and Grid trap: min-width: 0
This is the number one reason behind “overflow-wrap doesn’t work”. A flex item defaults to min-width: auto, meaning it never shrinks below the width of its widest content. With a fifty-character URL inside, the item keeps that width, and the break never happens because, as far as the item is concerned, the text fits.
/* Flexbox: a child won't shrink below the width of its longest word */
.media {
display: flex;
gap: 1rem;
}
.media__body {
min-width: 0; /* lets the item shrink */
overflow-wrap: anywhere;
}
/* Grid: 1fr means minmax(auto, 1fr), hence the same problem */
.layout {
display: grid;
grid-template-columns: 16rem minmax(0, 1fr);
}
Grid follows the same logic: 1fr is shorthand for minmax(auto, 1fr), so the track won’t go below its content’s minimum width. Writing minmax(0, 1fr) solves it. Bear it in mind with repeat(auto-fill, minmax(16rem, 1fr)) grids too: the minimum is explicit there, but the content of each card still needs to be able to break.
Tables work the same way: with table-layout: auto, a cell grows to fit its content. For data tables, table-layout: fixed with a set width makes the layout predictable; otherwise, let the table scroll inside its wrapper.
Clean breaks with hyphens and manual break points
Breaking a word anywhere fixes the overflow but isn’t pretty in a paragraph. hyphens: auto lets the browser hyphenate according to the language’s rules, with a hyphen at the end of the line. Two conditions: the lang attribute must be right on the page (or the element), and the browser needs a hyphenation dictionary for that language, which mainstream browsers have for English and French.
<!-- Automatic hyphenation needs to know the language -->
<html lang="en">
<style>
.entry-content p {
hyphens: auto;
overflow-wrap: anywhere; /* safety net for URLs */
}
.entry-content :is(h1, h2, h3) {
hyphens: manual; /* no automatic hyphenation in headings */
text-wrap: balance;
}
</style>
<!-- Manual break points: ­ shows a hyphen, <wbr> doesn't -->
<p>Counter­intelligence­operations</p>
<p>https://example.com/<wbr>documentation/<wbr>installation</p>
On a multilingual site, make sure each version declares its own language: an English article served with lang="fr" gets hyphenated by French rules, with odd results. We keep hyphenation out of headings, where a split word draws the eye, and use it mainly for justified text and narrow columns.
For one-off cases there are two manual tools: ­ (soft hyphen) marks where a word may break with a hyphen, and <wbr> marks where it may break without one, ideal for a displayed URL. In the WordPress editor, you add them by editing the block as HTML.
A baseline rule for your themes
On our WordPress themes, we always add a safety net to the areas where content comes from editors, plus specific handling for code and tables, which shouldn’t be broken but should scroll inside their own box:
/* Safety net we add to WordPress themes */
.entry-content,
.comment-content,
.widget {
overflow-wrap: anywhere;
}
/* Code keeps its formatting and scrolls inside its own box */
.entry-content pre {
max-width: 100%;
overflow-x: auto;
overflow-wrap: normal;
}
/* Wide tables: the wrapper scrolls, not the page */
.entry-content .wp-block-table {
overflow-x: auto;
}
The WordPress Table block already wraps the table in a figure; that’s what we let scroll, which keeps the table’s semantics intact. Avoid setting the table itself to display: block, which can strip its structure for screen readers.
To test, keep a set of “nasty” content to hand: a very long URL with query parameters, an extra-long work email address, a German compound noun, a product reference with no spaces. Paste them into a card, a menu, a table and a sidebar, then view the page at small-phone width. Five minutes of testing heads off most “the site is broken on my phone” reports.
FAQ
Why doesn’t overflow-wrap: anywhere work?
Almost always because the element is a flex or grid child that won’t shrink: add min-width: 0 to it, or use minmax(0, 1fr) in the grid. Also check that no white-space: nowrap rule is preventing wrapping altogether.
Should overflow-wrap: anywhere go on the whole page?
You can put it on body, and it’s harmless for running text. We prefer to target content areas and keep it away from code and from elements where a break would be awkward, such as short buttons or prices.
What about text-overflow: ellipsis?
That’s a different approach: instead of wrapping text over several lines, you truncate it with an ellipsis. Handy for a compact list or table, as long as the full text is available elsewhere, for instance on the detail page.
Does your layout break on mobile as soon as real content arrives? We audit and fix your WordPress theme’s CSS so it holds up on every screen size.



