Skip to content

Today I learned

How do I stop long URLs from causing horizontal scroll on mobile?

· updated #Web development

A bare URL or a long identifier in inline code is one unbreakable "word" to the browser. On a phone it ran past the column and gave the whole page a sideways scrollbar.

css
.prose {
  overflow-wrap: break-word;
}
.prose a,
.prose :not(pre) > code {
  overflow-wrap: anywhere; /* also shrinks min-content width */
}

body {
  overflow-x: clip; /* guard rail, not hidden */
}

Two details that matter:

  1. break-word only wraps once the line already overflows. It doesn't lower the element's min-content width, so inside a flex or grid item the column still stretches to the full URL. anywhere does, so it works there too. For flex rows, also put min-width: 0 on the text item.
  2. Use overflow-x: clip, not hidden. hidden turns the element into a scroll container (and the other axis becomes auto), which quietly breaks position: sticky headers. clip just cuts off the overflow.

Code blocks keep their own horizontal scroll, so only inline text wraps.

Hit this on the TIL pages of this site: one note with a long link widened every page on mobile.

Source: MDN: overflow-wrap, MDN: overflow clip

The 30-second version

Share LinkedIn Post on X

Related notes

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.