help1
shopify horizontal scrollshopifycsshorizon-theme

The Shopify Horizontal Scroll Fix That Broke Malin's Header

A one-line Shopify horizontal scroll fix removed the scrollbar and killed Malin's sticky header. Here is why, and the one-word change that fixes both.

help1 Team
The Shopify Horizontal Scroll Fix That Broke Malin's Header

Malin sells vintage posters and film ephemera out of a narrow second-floor shop on Magasinsgatan in Gothenburg. About 400 SKUs, half of them one-of-one items she has photographed on her phone, the other half small reprints she handles in batches of thirty. Six years on Squarespace, three months on Shopify. She picked Horizon because the gallery-style product cards did more work for a poster store than Dawn's grid.

A customer emailed her on a Monday morning from a bus in Lund. He was trying to buy a Bergman festival print on his phone and the page kept sliding sideways when he scrolled. He attached a screenshot. On the right edge of the page there was a thin grey strip of nothing, and under it a scrollbar with no content sitting below it. The kind of thing a careful shopper closes the tab over.

Malin had never seen it in the theme editor preview. She had never seen it on her desktop. She opened her own phone, loaded the storefront, and saw exactly what the customer had sent: a horizontal scroll she had not approved of, on every page.

What Malin had tried

She did the thing any solo merchant does. She opened Google, typed "shopify horizontal scroll fix," and read the top three community threads. All three recommended the same snippet:

html, body {
  overflow-x: hidden;
}

She pasted it into Online Store > Themes > Customize > Theme Settings > Custom CSS. Saved. Reloaded the mobile site. The scrollbar was gone. The slight sideways drift when she scrolled the Bergman page was gone. She wrote the customer back inside an hour, thanked him for the screenshot, and told him she had sorted it out.

For three days, she had. She made a few sales. It was the kind of Wednesday a merchant does not remember unless something later turns it into a landmark.

What happened on Thursday

A different customer wrote in. The sticky "Add to cart" bar she had turned on in Horizon's product settings, the strip that was supposed to follow a shopper down the page on mobile, had stopped sticking. It appeared at the top of the page, scrolled away as the shopper read down the product description, and never came back. On product pages where she had written long paragraphs about paper stock and printing history to tell her shop apart from the Etsy sellers, the Add to Cart button was now offscreen for roughly half the read.

Malin had not touched the sticky setting. The theme code had not updated. Nothing else in her store had changed. The only thing that had changed was the three lines of CSS at the top of her Custom CSS panel.

She searched again, this time for "shopify sticky header not working," and found a thread that solved itself in one sentence. The merchant in that thread, running Dawn 13, had the same symptom and the same recent history: a horizontal scroll fix with overflow-x: hidden on html and body. The reply they accepted was three words long. "Change hidden to clip."

She tried it. The sticky bar started sticking again. The horizontal scroll came back.

Why that pattern is everywhere in the shopify horizontal scroll threads

Most of the community answers to a shopify horizontal scroll complaint are correct about the mechanism and wrong about the fix. The mechanism is almost never mysterious: one element on the page is wider than the viewport, and the browser gives you a scrollbar so you can reach the rest of it. The fix the threads reach for is to tell the root of the document to hide any content past the right edge. That works, in the narrow sense that it removes the scrollbar.

The reason it breaks sticky positioning is quieter and lives in the CSS spec. When you apply overflow: hidden to an ancestor, you create a new scroll container. position: sticky only sticks within the nearest ancestor that does not create a scroll container. Hide overflow on html or body and every sticky element under them, from Horizon's "Add to cart" bar to Dawn's sticky header, politely stops working. There is no warning. No error in the admin. The sticky setting still shows as on.

The second footgun is specific to clip. If you set overflow-x: clip on html but leave overflow-y at its default, the CSS specification can promote the implicit overflow-y: visible to auto and then treat clip as hidden on the x axis. The behaviour depends on the browser and the context. The safer form is to set both axes explicitly, so the intent is not ambiguous:

html {
  overflow-x: clip;
  overflow-y: visible;
}

That is a one-line difference from what most of the threads tell you to paste, and it is the difference between a sticky header and no sticky header.

The thing that finally fixed it

When Malin opened a chat, the first thing I asked was for her to pull up her live storefront in Chrome on a desktop. Not the theme editor, which runs in its own fixed-width container and does not reproduce mobile overflow reliably. Then press F12, go to the Console tab, and paste this:

[...document.querySelectorAll('*')].filter(e => {
  let r = e.getBoundingClientRect().right;
  if (r > window.innerWidth) { console.log(r, e); }
});

That snippet has been passed around the Shopify community forums for years as the first thing to run when a page scrolls sideways and nobody knows why. It walks every element on the page, measures the right edge, and prints anything whose right edge is past the viewport's right edge. If the list is empty, the cause is not element width and the fix will not be an overflow rule at all.

On Malin's storefront, one line printed:

403 <div class="ai-carousel-container ai-carousel-9f8d7...">

She had installed an AI-powered product recommendation app a few days before the Monday email. The carousel it injected into her product page was declared at width: 100vw. On her phone's Chrome, where the browser reserves roughly 15 pixels for the vertical scrollbar and 100vw includes that strip, the carousel was 15 pixels wider than the body. Enough to create a horizontal scroll, not enough to look visually wrong.

The fix was two blocks of CSS, pasted into the same Custom CSS box she had opened three days earlier:

[class*="ai-carousel-container"] {
  display: block;
  max-width: 100%;
  overflow-x: hidden;
}
html, body {
  overflow-x: clip;
  overflow-y: visible;
}

Two things in there worth naming. The first is the swap from hidden to clip at the root. The second is the substring selector [class*="ai-carousel-container"]. The AI apps that have been showing up in shopify horizontal scroll threads for the last year, the endless scroller app, the hotspot popup, the carousel, inject class names with a short per-store hash appended. Match the substring and the rule survives the next time the hash rotates. Match the full class and you get exactly one deploy of silence before the horizontal scroll comes back.

After she saved, the console snippet returned no rows. The scrollbar was gone. The sticky Add to cart came back on its own, because the sticky behaviour was never broken, only prevented. Remove the prevention and the browser does the rest.

What this means for your store

If you have a shopify horizontal scroll on mobile and you are about to paste html, body { overflow-x: hidden; }, do three things first.

  1. Open Chrome on a desktop, load your live storefront, press F12, and run the console snippet above. Anything that prints is a candidate. If nothing prints and you still see horizontal scroll on a product page, suspect the Dawn product-media slider's scroll-padding-left, which produces the same symptom with a different cause and a different fix.
  2. Decide whether the offending element is one you own or one an app injected. If an app injected it, note the class name prefix. On three different Horizon threads over the last twelve months, the culprit was a class name starting with ai-. If yours starts with a vendor prefix, you have a second job later: tell the app's support that their container needs max-width: 100%. Your CSS workaround will hold until they rotate the class name again, and they will.
  3. Make the overflow rule two layered things, not one. Scope overflow-x: hidden to the specific element you identified. At the root, use overflow-x: clip with an explicit overflow-y: visible. That combination removes the horizontal scroll and leaves Horizon's sticky "Add to cart" bar, Dawn's sticky header, and your scrolling announcement banner working the way the theme settings imply they will.

A side note for Dawn stores: Dawn versions earlier than 10.0.0 shipped with their own horizontal scroll bug in the announcement bar slider, fixed by the Shopify theme team in a May 2023 PR. If your scroll began life after a theme update, confirm the theme is on the current version before writing any custom CSS at all. I have watched more than one merchant write a careful overflow rule that was really just repairing something the theme had already fixed upstream for them.

And one honest limitation. I have not tested the [class*="ai-"] prefix selector on Shopify Plus stores running the Checkout Extensibility apps that also use ai--prefixed utility classes. On a Plus store, tighten the selector to the specific carousel vendor and avoid matching anything in the checkout tree. If you want a second pair of eyes before you paste CSS into a store that is already converting, the first 15 minutes with a help1 expert is free and this is one of the cases that fits inside those 15 minutes most of the time. If you want adjacent reading first, I wrote earlier about a Shopify sticky Add to Cart that looked fine on desktop and quietly cost sales on mobile and the diagnostic path overlaps with this one.

Malin's shop has been clean on mobile for about six weeks now. A graphic designer in Malmö emailed to say the mobile site was "actually pleasant to use," which she framed and put over her workbench. The Monday-morning customer on the bus to Lund never came back for the Bergman print; he went quiet after her thank-you reply. She likes to think he will circle back for the Ingmar centenary. She has stopped looking at the bottom of her phone browser first thing every morning to check for a scrollbar that is not there, which she had not realised she was doing until she stopped.

Still stuck? Talk to an expert.

Our vetted Shopify experts can fix this issue for you in a live session. $39 per session. Your first 15 minutes are free.