By Daniel Okafor, NBT
The site looks perfect on your laptop. On a phone, you swipe down and the whole page wobbles left and right. Pinch out and there's a strip of empty space down the right side. Sometimes the header looks a few pixels too narrow for the screen.
That's horizontal overflow: one element is wider than the viewport, and the browser makes the whole page wide enough to fit it. It's very common when you build a website with AI, because generated layouts often use fixed widths, full-width tricks and decorative shapes that look fine on a wide screen. The good news is that it's usually one or two elements, and you can find them in a couple of minutes.
Step 1: Reproduce it on the desktop
You don't need to keep testing on your phone. Open Chrome or Firefox developer tools, switch on the device toolbar (responsive mode), and pick a narrow width such as 360 px. Scroll to the bottom of the page and try scrolling sideways with a trackpad. If the page moves, you have overflow.
Also check that your page has the viewport tag in its <head>. Without it, phones render the page as a wide desktop page and zoom out, which looks like a different problem:
<meta name="viewport" content="width=device-width, initial-scale=1"> Step 2: Find the wide element with one snippet
Paste this in the developer tools console. It lists every element whose right edge goes past the window:
const vw = document.documentElement.clientWidth; [...document.querySelectorAll('body *')] .filter((el) => el.getBoundingClientRect().right > vw + 1) .forEach((el) => console.log(el, Math.round(el.getBoundingClientRect().right))); Hover each logged element and the browser highlights it on the page. Look for the outermost ones. When a container is too wide, all of its children show up too, so start from the top of the list and work down.
A second quick trick: add this rule temporarily in the styles panel to outline everything, then scroll right and see which box sticks out:
* { outline: 1px solid red; } Step 3: Fix the usual culprits
These are the patterns that cause most overflow in AI-generated pages.
Fixed widths. A card or section with width: 1200px or min-width: 600px. Replace it with a maximum:
.container { width: 100%; max-width: 1200px; margin-inline: auto; } 100vw for full-width sections. On desktops with visible scrollbars, 100vw includes the scrollbar's width, so a 100vw section is slightly wider than the page. Use width: 100% on a section that's already a direct child of the body, or avoid the full-bleed trick where you don't need it.
Images and videos without limits. A large image in its natural size pushes everything wider. A short base rule fixes it across the site:
img, video, iframe { max-width: 100%; height: auto; } (For iframes such as embedded maps, height: auto may collapse them; give those a fixed height or an aspect-ratio.)
Long words and URLs. A long link, email address or code string doesn't wrap by default:
.content { overflow-wrap: anywhere; } pre { overflow-x: auto; } overflow-wrap: anywhere lets long strings break; pre blocks get their own scrollbar instead of widening the page.
Flex and grid items that refuse to shrink. A flex child defaults to min-width: auto, so it can't shrink below its content's width. A row with a long title or a wide table inside often overflows because of this:
.row > * { min-width: 0; } For grids, grid-template-columns: repeat(3, 1fr) can do the same thing; minmax(0, 1fr) lets columns shrink.
Decorative shapes and animations. Blurry gradient blobs, rotated banners and slide-in animations often sit partly off-screen. Put them inside a parent with overflow: hidden (or overflow: clip) so they're cut off at the edge.
Negative margins. Utility classes like -mx-8 on a row, without matching padding on its parent, push content out past the edge.
Step 4: Don't hide it on the body
The tempting fix is:
body { overflow-x: hidden; } It hides the symptom, but the wide element is still there, its content is still cut off, and on some browsers it can break position: sticky on your header. Use it only after you've fixed the real cause, and prefer overflow: clip on the specific section that has the decorative overflow.
Step 5: Check the widths that matter
After fixing, test at a few widths in responsive mode: 320 px (small phones), 360 px and 390 px (common phones), 768 px (tablets in portrait), and one desktop width. Rerun the console snippet at each. An empty result means nothing sticks out.
Then open the site on a real phone once, rotate it, and scroll through every page. Menus that open off-canvas, cookie banners and chat widgets often only overflow when they're open, so open them too.
Step 6: Ask the AI for the fix, not a rewrite
Once you know the element, give the AI tool a precise request:
On screens narrower than 400 px,
.pricing-rowis wider than the viewport (right edge at 512 px). Find the cause in its CSS and fix it without changing the desktop layout. Don't addoverflow-x: hiddentobodyorhtml.
The measured number and the "don't hide it" rule keep the fix targeted, instead of a redesign of the section.
A short checklist
- Viewport meta tag present.
- Responsive mode at 360 px; scroll sideways to confirm.
- Console snippet to list elements past the right edge.
- Replace fixed widths with
max-width, avoid100vw, cap images. -
min-width: 0on flex children,minmax(0, 1fr)in grids. - Clip decorative shapes on their own section, not on the body.
Layout polish like this is one of the steps in a step-by-step guide to build a website with AI, from the first prompt to a site you can share.

