Page wider than screen CSS problems usually happen when one hidden element is wider than the viewport: a 100vw section, fixed-width card, grid column, image, flex row, long text, or absolute element.
Horizontal Overflow Fix
Why is my page wider than the screen?
A page becomes wider than the screen when one element quietly escapes the viewport. The annoying part is that the whole layout may look fine at first, but the browser still allows sideways scrolling because a single section, card, image, grid, button, or line of text is too wide.
- Horizontal scroll
- 100vw bug
- Fixed width
- Mobile overflow
What the bug looks like
The page has a sideways scroll bar, content feels zoomed out, or the mobile screen can slide left and right.
Why it happens
One element is wider than its parent or the viewport, even if the rest of the design looks normal.
What usually fixes it
Replace fixed widths with fluid widths, avoid unsafe 100vw, allow grid/flex items to shrink, and wrap long content.
width:100vw creates horizontal overflow
A full-width section often looks harmless, but 100vw can be wider than the visible content area. When the page has a vertical scrollbar, 100vw may include that scrollbar width and push the layout sideways.
Broken code
Unsafe viewport width.hero {
width: 100vw;
padding: 24px;
}
Broken visual result
This strip is wider than the visible screen.
Correct code
Safe full width.hero {
width: 100%;
max-width: 100%;
padding: 24px;
}
Fixed visual result
The element respects the available width.
width:100% for normal full-width sections inside the page flow.A fixed-width element is too wide for mobile
A desktop card, modal, table, button, image, or pricing box can keep a fixed width on mobile. Once that width is larger than the screen, the entire page becomes wider too.
Broken code
Fixed desktop width.pricing-card {
width: 420px;
padding: 24px;
}
Broken visual result
This card keeps a desktop width and escapes the viewport.
Correct code
Fluid max width.pricing-card {
width: min(100%, 420px);
padding: 24px;
}
Fixed visual result
The card can be 420px on desktop but shrink on mobile.
width:min(100%, 420px) keeps the design responsive without losing the desktop max width.Grid columns are wider than the screen
CSS Grid can create overflow when columns are fixed or when grid items refuse to shrink. The fix is usually to use responsive columns and allow content to shrink with minmax(0,1fr).
Broken code
Fixed grid columns.cards {
display: grid;
grid-template-columns: repeat(3, 220px);
gap: 24px;
}
Broken visual result
Correct code
Responsive grid.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
gap: 24px;
}
.cards > * {
min-width: 0;
}
Fixed visual result
Long text, URLs, or code do not wrap
Sometimes the layout is fine, but one long string forces overflow. This happens with URLs, code snippets, email addresses, product names, buttons, file paths, and long words.
Broken code
No wrapping.content-title {
white-space: nowrap;
}
Broken visual result
Correct code
Safe wrapping.content-title {
overflow-wrap: anywhere;
min-width: 0;
}
Fixed visual result
overflow-wrap:anywhere prevents one long string from controlling the whole page width.A production-minded anti-overflow pattern
A stronger layout pattern does not hide overflow as the first move. It prevents overflow by using safe wrappers, fluid widths, shrinkable grid/flex children, wrapping text, and media-safe containers.
Premium code
Safe responsive systemhtml,
body {
max-width: 100%;
}
.page-section {
width: 100%;
max-width: 100%;
padding-inline: clamp(16px, 4vw, 32px);
}
.wrapper {
width: min(100%, 1120px);
margin-inline: auto;
}
.card,
.media,
.button,
.input {
max-width: 100%;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
gap: 24px;
}
.grid > *,
.flex > * {
min-width: 0;
}
.long-content {
overflow-wrap: anywhere;
}
Premium visual result
Fast practical rule
If your page is wider than the screen, search for the element that sticks out. Open DevTools, inspect wide sections, check fixed widths, replace unsafe 100vw, add min-width:0 to grid or flex children, and make long text wrap.
Debug checklist
- Temporarily add
* { outline: 1px solid red; }in DevTools to spot the leaking element. - Check if any section uses
width:100vwinstead ofwidth:100%. - Look for fixed widths on cards, buttons, images, modals, tables, and containers.
- Make large elements fluid with
width:min(100%, value)ormax-width:100%. - For CSS Grid, avoid fixed mobile columns and use
minmax(0,1fr)or responsive columns. - For Flexbox, check
flex-wrap,gap,flex-basis, andmin-width:0. - Wrap long URLs, code, and product names with
overflow-wrap:anywhere. - Inspect absolute or decorative elements positioned outside the viewport.
- Avoid using
overflow-x:hiddenas the only fix unless you already found the real cause.
width:100vw on a page that already has a vertical scrollbar.
Final takeaway
A page wider than the screen is almost always caused by one element that is wider than its parent or the viewport. The whole site feels broken, but the real bug is usually a single fixed width, unsafe 100vw, grid column, flex row, image, absolute element, or long unwrapped text.
Do not start by hiding horizontal overflow everywhere. Find the leaking element first, make it responsive, and then use global overflow rules only as a last protective layer.
Want more fixes like this?
Browse more CSS and responsive debugging guides in the FrontFixer library.