Responsive layouts have to accommodate long content as well as small screens. CSS horizontal overflow can be fixed at the oversized element, keeping a long URL visible without making the whole page scroll sideways.

A flex item's automatic minimum size can keep it wider than the space available in its row. Long filenames inside URLs make this particularly noticeable because the browser has few places to break the text. Hiding page overflow conceals the symptom and can clip content or focus outlines instead of repairing the layout.

A small local flex card isolates this failure without changing a working site. A text editor and Chrome are enough to reproduce it and inspect the affected element; the same CSS repair belongs on the corresponding flex child and text element in an existing project.

Steps to fix CSS horizontal overflow:

  1. Create a file named overflow.html in a local folder using your text editor.
    overflow.html
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>Release card</title>
      <style>
    /* Card styles go here. */
      </style>
    </head>
    <body>
      <main>
        <h1>Release files</h1>
        <div class="card">
          <span class="card__icon" aria-hidden="true">↓</span>
          <div class="card__body">
            <h2>Latest release</h2>
            <a class="card__url" href="https://example.com/releases/2026/desktopapplicationlinuxx8664withdebugsymbols20261108.tar.gz">https://example.com/releases/2026/desktopapplicationlinuxx8664withdebugsymbols20261108.tar.gz</a>
          </div>
        </div>
      </main>
    </body>
    </html>
  2. Replace the Card styles go here comment inside the file's <style> element with the card's initial CSS.
    * { box-sizing: border-box; }
    body { margin: 24px; font: 18px/1.5 sans-serif; color: #17324d; }
    main { max-inline-size: 24rem; }
    h1 { font-size: 26px; }
    h2 { margin: 0 0 8px; font-size: 20px; }
    a { color: #075a9c; }
    .card {
      display: flex;
      gap: 16px;
      padding: 16px;
      border: 2px solid #52738f;
      border-radius: 8px;
    }
    .card__icon { flex: 0 0 32px; font-size: 28px; }
    .card__body { flex: 1; }

    The icon keeps its width while the text area takes the remaining space. The long filename exposes the text area's automatic minimum size.

  3. Save overflow.html in your text editor.
  4. Open the saved overflow.html file in Chrome.

    At a narrow browser width, the URL extends past the card and produces horizontal page scrolling.

  5. Inspect the Latest release heading with Chrome's Inspect command.

    The heading's context menu contains Inspect, which opens the Elements panel on that element.

  6. Select the heading's parent div.card__body in the Elements tree.

    The Styles pane shows .card__body { flex: 1; }. Its automatic minimum size still follows the long content, so the text area extends beyond the card despite being a flexible item.

  7. Replace the .card__body rule in overflow.html with the shrinking and wrapping rules.
    .card__body {
      flex: 1;
      min-inline-size: 0;
    }
    .card__url {
      overflow-wrap: anywhere;
    }

    min-inline-size: 0 permits the flex child to shrink below its content's intrinsic width. overflow-wrap: anywhere permits breaks within the long filename so the text stays inside that smaller box. The rules belong on the flexible text area and its URL, leaving the icon and other page content alone.

    A grid layout with the same minimum-size problem may also need a flexible track defined as minmax(0, 1fr).
    Related: How to create a two-column CSS grid layout

  8. Save the corrected overflow.html file.
  9. Reload overflow.html in Chrome at the width that showed the overflow.
  10. Confirm that the complete URL wraps inside the card without horizontal page scrolling.

    The filename ends in .tar.gz inside the card, and the page's horizontal scrollbar is gone. The link remains visible and keyboard focus is not clipped. If the original symptom remains on an existing site, another element or an overriding CSS rule still needs inspection.

Share this guide