Why Does an Offscreen Menu Create Horizontal Scroll?

Offscreen menu horizontal scroll usually happens when a hidden mobile menu is pushed outside the viewport with negative offsets, left:100%, right:-280px, translateX(), or an oversized backdrop.

Mobile Menu Overflow Fix

Why does an offscreen menu create horizontal scroll?

An offscreen menu can create horizontal scroll even when it is closed. The menu may look hidden because it sits outside the visible screen, but its box can still contribute to the scrollable width of the page. This is common in mobile navigation, slide-out panels, account drawers, filter sidebars, and cart menus.

The bug usually appears after a developer tries to hide a menu by moving it away from the viewport. A rule like right:-280px or transform:translateX(100%) feels logical because the panel disappears visually. But if the element is still attached to the page in a way that expands the scrollable area, the user gets a sideways page instead of a clean closed menu.

  • Offscreen menu
  • Mobile navigation
  • Horizontal scroll
  • CSS transform

Test the hidden state, not only the open state

Many offscreen menu bugs happen while the menu is closed. Paste the closed menu CSS into a controlled preview and disable the offscreen offset, transform, or fixed width. If the horizontal scrollbar disappears, the hidden menu is not really hidden from the scrollable layout.

Related: Try this in the FrontFixer Live Inspector.

Open Live Inspector

What the bug looks like

The page slides sideways on mobile, often even before the menu is opened.

Why it happens

The menu is hidden by moving it offscreen instead of keeping it inside a safe fixed layer.

What usually fixes it

Use a fixed drawer, safe width, transform-based state, and clip the drawer system intentionally.

Why hiding a menu offscreen is not always safe

A mobile drawer is usually meant to feel like it lives outside the screen until the user taps the menu button. That design pattern is normal. The mistake is treating “outside the visible screen” as the same thing as “not affecting layout.” CSS does not always work that way. A positioned element can be visually outside the viewport and still become part of the scrollable overflow area.

The safest mental model is this: the menu should be a fixed overlay system, not a normal page section that has been shoved to the side. If the drawer belongs to the overlay layer, it should be positioned with position:fixed, bounded by the viewport, and moved with a controlled transform. If the drawer is treated like a normal block inside the document, it is much easier for its width and offset to widen the page.

Do not judge the menu only by whether it is visible. Judge it by whether the page remains the same width when the menu is closed, opening, and open. A clean offscreen menu should not create a horizontal scrollbar in any of those states.

Closed still mattersThe closed state can be the state that creates the scroll bug.
Fixed is usually saferA drawer tied to the viewport is easier to control than one sitting in normal document flow.
Width must be fluidUse min() or max-width so the panel never beats the phone.
Hide with state, not chaosMove the menu predictably and keep the page width stable.
Error 1

The drawer is hidden with a negative right value

This is the classic mobile drawer bug. The menu is positioned on the right side and hidden with a negative value. Visually, the drawer disappears, but the page may still become wider than the screen because the drawer is sitting outside the safe viewport.

Broken code

Negative right
.mobile-drawer {
  position: absolute;
  top: 0;
  right: -280px;
  width: 280px;
}

Broken visual result

Drawer leaks outside
overflow
Mobile page

The content fits, but the hidden drawer is still outside.

MenuHomeGuidesContact
The drawer is hidden visually, but the right-side leak creates horizontal scroll.

Correct code

Fixed drawer
.mobile-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(280px, 86vw);
  transform: translateX(100%);
}

.mobile-drawer.is-open {
  transform: translateX(0);
}

Fixed visual result

Viewport owns drawer
safe
Mobile page

The drawer is controlled by the viewport, not document width.

MenuHomeGuidesContact
Use a fixed drawer with fluid width and transform state instead of a negative page offset.
Error 2

The menu is placed at left:100%

Another common pattern hides the menu by placing its left edge at the end of the parent. That can be fine inside a clipped overlay, but if the element is attached to the document, it may create a full extra panel width beyond the viewport.

Broken code

Left 100%
.drawer {
  position: absolute;
  left: 100%;
  top: 0;
  width: 260px;
}

Broken visual result

Extra panel width
left:100%
Content area

The hidden drawer begins after the viewport edge.

DrawerProfileSettingsLogout
The menu starts after the page width, then adds its own width on top.

Correct code

Translate inside fixed layer
.drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(260px, 86vw);
  transform: translateX(100%);
}

.drawer.is-open {
  transform: translateX(0);
}

Fixed visual result

No extra document width
stable
Content area

The drawer belongs to an overlay layer and does not widen the page.

DrawerProfileSettingsLogout
The drawer can still slide, but the document width stays unchanged.
Error 3

The backdrop or menu strip is wider than the viewport

Sometimes the drawer is not the only problem. A backdrop, menu strip, or inner navigation row may use 100vw plus padding, a negative right value, or a fixed desktop width. The menu system then creates overflow even if the panel itself seems reasonable.

Broken code

Oversized menu layer
.menu-backdrop {
  position: fixed;
  inset: 0;
  width: calc(100vw + 70px);
}

.menu-strip {
  position: absolute;
  left: 18px;
  right: -80px;
}

Broken visual result

Backdrop leaks
wide layer
Menu overlay

The overlay layer itself is wider than the screen.

HomeServicesContact
The backdrop and strip create overflow even if the drawer is not visible yet.

Correct code

Bounded overlay
.menu-backdrop {
  position: fixed;
  inset: 0;
  width: auto;
}

.menu-strip {
  position: absolute;
  left: 18px;
  right: 18px;
  max-width: calc(100% - 36px);
}

Fixed visual result

Overlay is bounded
fits
Menu overlay

The overlay uses the viewport without exceeding it.

HomeServicesContact
Use inset:0 and safe inner spacing instead of widening the overlay manually.
Error 4

The transform distance is based on the wrong box

Transform-based drawers are usually better than negative offsets, but they still need the right containing layer. If the panel is inside a normal page wrapper or has a desktop-sized width, translating it can still leave a visible or scrollable leak. The panel should be sized for the viewport and transformed from a fixed edge.

Broken code

Wrong transform context
.drawer {
  position: absolute;
  right: 18px;
  width: 320px;
  transform: translateX(82%);
}

Broken visual result

Transform still leaks
translated
Sliding drawer

The drawer is translated from a box that is already too wide.

PanelSearchFiltersApply
A transform is not automatically safe if the drawer width and position are unsafe.

Correct code

Safe transform state
.drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(320px, 88vw);
  transform: translateX(100%);
}

.drawer.is-open {
  transform: translateX(0);
}

Fixed visual result

Transform is controlled
safe
Sliding drawer

The transform belongs to a viewport-sized drawer system.

PanelSearchFiltersApply
Size the drawer safely first, then animate the state with transform.
Premium pattern

A production-minded offscreen menu pattern

A strong offscreen menu keeps the drawer in a fixed overlay layer, uses a fluid width, moves with transform, avoids negative document offsets, locks page interaction intentionally, and never relies on the body hiding horizontal overflow to cover a bad menu state.

Premium code

Safe drawer system
.drawer-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: clip;
  z-index: 1000;
}

.drawer-layer.is-open {
  pointer-events: auto;
}

.drawer {
  position: absolute;
  inset: 0 0 0 auto;
  width: min(340px, 88vw);
  max-width: 100%;
  transform: translateX(100%);
  transition: transform .22s ease;
}

.drawer-layer.is-open .drawer {
  transform: translateX(0);
}

Premium visual result

Drawer layer, no page leak
premium
Safe drawer layer

The page width stays stable while the drawer opens and closes.

Fixed layer
Fluid drawer
Transform state
No overflow
MenuHomeFixesTools
Premium drawer CSS does not hide a broken layout. It creates a safe overlay system from the start.

Fast practical rule

If an offscreen menu creates horizontal scroll, do not start by adding overflow-x:hidden to the whole site. First test the closed menu state. Remove negative offsets, replace document-based positioning with a fixed overlay layer, make the drawer width fluid, and move the drawer with a controlled transform.

Debug checklist

  • Inspect the closed menu state, not only the open menu state.
  • Search for right:-, left:100%, left:100vw, and large translate values.
  • Check whether the drawer is absolute inside the document instead of fixed to the viewport.
  • Replace fixed drawer widths with width:min(340px, 88vw) or a similar safe value.
  • Use inset:0 for the overlay layer instead of manually setting oversized viewport widths.
  • Keep the backdrop, drawer, and inner menu strips bounded to the same viewport layer.
  • Avoid solving the problem only with body { overflow-x:hidden; }.
  • Test the page width while the menu is closed, opening, and fully open.
Best first moveTemporarily remove the drawer from the DOM. If scroll disappears, the menu system is the source.
Most common causeA closed drawer is hidden with a negative right value or left:100%.
Most sneaky causeThe backdrop or inner menu strip is wider than the viewport.
Better mindsetA drawer should be an overlay layer, not a normal page element pushed sideways.

Final takeaway

An offscreen menu creates horizontal scroll when the closed state still occupies or leaks into scrollable space. The menu may look hidden, but if its box sits outside the viewport with negative offsets, oversized widths, or unsafe transforms, the page can become wider than the screen.

Build the drawer as a fixed overlay layer, give it a fluid width, keep the backdrop bounded, and animate with transform inside a safe system. That lets the menu slide without dragging the entire document width along with it.

The cleanest test is simple: the document should not become wider when the menu component exists on the page. A closed drawer, an open drawer, and an animating drawer should all preserve the same viewport width. If any state creates sideways scroll, the drawer system still needs safer boundaries.

Want more fixes like this?

Browse more mobile menu, overflow, and responsive CSS debugging guides in the FrontFixer library.