# One CSS line fixes the long link that breaks mobile layout

> overflow-wrap: anywhere lets a flex item shrink past its content width.

Source: https://fullbytedeveloper.com/blog/urlbreak
Published here: 2026-11-14

One pasted link made a page scroll sideways on a phone. One CSS line fixed it.

## The problem

A comment with a 120 character link, in a flex row next to an avatar, on a 375 px wide phone screen (Chrome 156, phone emulation). The page grew to 757 px and panned 382 px sideways.

## The fix

```css
.comment {
  overflow-wrap: anywhere;
}
```

## Measured widths

| Rule | Width |
|------|-------|
| no rule | 757 px (broken) |
| overflow-wrap: break-word | 757 px (still broken in flex row) |
| overflow-wrap: anywhere | 375 px (fixed) |
| break-word plus min-width: 0 | 375 px (also fixed) |

## Why break-word failed

In a flex or grid item, `min-width: auto` means the box will not go narrower than its min-content size. MDN: with `anywhere`, the extra break points "are considered when calculating min-content intrinsic sizes". With `break-word` they are "NOT considered". So the box cannot shrink and the link pushes the page wide. In a plain block, break-word worked fine (375 px).

## The check

Paste in the console:

```javascript
document.documentElement.scrollWidth > document.documentElement.clientWidth
```

`true` = still sideways. `false` = fixed.

Tip: on phone emulation, `window.innerWidth` grew to 757 with the page, so `scrollWidth > innerWidth` said false on the broken page. Compare with `clientWidth` instead.

## Browser support

`overflow-wrap: anywhere` works in Chrome 80+, Firefox 65+ and Safari 15.4+ (MDN compat data). On older Safari, `break-word` plus `min-width: 0` is the fallback.

Send this to the friend whose page scrolls sideways on phones because of one long link.

## Sources

1. [MDN: overflow-wrap](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap)
2. [MDN: min-width](https://developer.mozilla.org/en-US/docs/Web/CSS/min-width)
3. [MDN: Element.clientWidth](https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth)
