A layout shift by 1px in CSS usually happens when the browser is forced to round fractional pixels, handle scrollbar width, calculate flexible columns, or switch between responsive rules at certain screen widths.
Responsive CSS Fix
Why Does My Layout Shift by 1px at Certain Screen Widths?
A layout shift by 1px can be hard to notice, but easy to feel. A card looks slightly off. A header no longer lines up with the content. A full-width section creates a tiny horizontal jump. The layout is not completely broken, but it feels unstable. The cause is usually CSS sizing math: 100vw, scrollbars, subpixel rounding, padding, borders, Grid, Flexbox, or a breakpoint that changes too much at once.
- 1px layout shift
- Responsive CSS bug
- Visual debugging
What the bug looks like
A container, card, navigation, button group, image area, or header moves slightly when the screen width changes.
Why it happens
CSS often calculates fractional widths, but the screen still has to paint real pixels. That conversion can expose tiny alignment issues.
What fixes it
Use safer width rules, stabilize scrollbars, apply consistent box sizing, and make Grid or Flexbox layouts more forgiving.
The FrontFixer visual rule for this bug
A 1px layout shift is easier to understand when you compare the code with what actually happens on the page. So this fix uses the same pattern for every common cause: first the broken code, then the broken visual result, then the corrected code, then the corrected visual result.
Use this mental model when debugging: the browser is not moving things randomly. Something in your CSS is creating a slightly different measurement than you expected.
Using 100vw when the page needs 100%
One of the most common causes of a tiny layout shift is using width:100vw on a section that should simply follow the normal page width. On desktop, 100vw can include the scrollbar area. That means the section may become slightly wider than the content area.
Broken code
100vw trap.hero { width: 100vw; margin-left: calc(50% - 50vw); padding: 64px 24px; } .container { max-width: 1120px; margin: 0 auto; } Broken visual result
Correct code
Safer width.hero { width: 100%; padding: 64px 24px; } .container { width: min(100% - 32px, 1120px); margin-inline: auto; } Fixed visual result
Forgetting box-sizing:border-box
Another common cause of small layout movement is the box model. If you give an element a width and then add padding and border, the final rendered size can become larger than expected. Sometimes the overflow is obvious. Other times it starts as a tiny visual mismatch.
Broken code
Width plus padding.card { width: 300px; padding: 24px; border: 1px solid #ddd; } Broken visual result
Correct code
Stable box model*, *::before, *::after { box-sizing: border-box; } .card { width: 300px; padding: 24px; border: 1px solid #ddd; } Fixed visual result
Letting Grid and Flexbox fight fractional pixels
Grid and Flexbox distribute available space. If the available width does not divide cleanly, the browser has to decide where the leftover pixel goes. That is why one column, tab, or button can sometimes look one pixel wider or slightly off.
Broken code
Tight grid math.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; } .card { min-width: auto; } Broken visual result
Correct code
Safer grid.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; } .grid > * { min-width: 0; } Fixed visual result
Making breakpoints too jumpy
Sometimes the 1px shift is not really a rounding issue. It is a breakpoint issue. The layout changes at a specific width, and that change makes the page look like it jumped. This is common around widths like 1366px, 1280px, 1024px, or any custom breakpoint.
Broken code
Jumpy breakpoint.container { max-width: 1200px; padding-inline: 32px; } @media (max-width: 1366px) { .container { max-width: 1180px; padding-inline: 31px; } } Broken visual result
Correct code
Fluid container.container { width: min(100% - 32px, 1200px); margin-inline: auto; } Fixed visual result
Ignoring scrollbar appearance and disappearance
A layout can shift when the vertical scrollbar appears or disappears. This often happens when a modal opens, content loads, tabs switch, accordions expand, or a page changes from short to scrollable. The content area becomes slightly different, and centered elements can appear to move.
Broken code
No scrollbar stabilityhtml { overflow-y: auto; } .modal-open { overflow: hidden; } Broken visual result
Correct code
Stable gutterhtml { scrollbar-gutter: stable; } /* Test browser support for your audience. */ Fixed visual result
Fast practical rule
If your layout shift is only 1px, do not patch it with margin-left:-1px or random transforms first. A tiny visual bug usually has a tiny math cause: 100vw, scrollbar width, fractional columns, box sizing, padding, borders, or a breakpoint that changes the layout too sharply.
How to debug the exact layout shift
Start by resizing the browser slowly. Watch the exact width where the layout shift appears. If it happens around a breakpoint, inspect the media query. If it happens when the page becomes scrollable, inspect scrollbar behavior. If it happens across many widths, look for fractional Grid, Flexbox, or percentage math.
Then inspect the element that moved. Check its computed width, margin, padding, border, transform, and parent container. The goal is to find which measurement changed by that tiny amount.
Temporary debug CSS
Debug only* { outline: 1px solid rgba(255, 0, 0, 0.15); } html, body { overflow-x: clip; } Use outlines temporarily to see which element is wider or misaligned. Remove debug outlines before shipping the page.
Debug checklist
- Check whether any section uses
width:100vwwhenwidth:100%would be safer. - Check if the layout shifts when the vertical scrollbar appears or disappears.
- Add
box-sizing:border-boxglobally if the project does not already use it. - Inspect the exact viewport width where the 1px shift starts.
- Look for media queries that change padding, gap, max width, or column count at that width.
- Check if Grid columns use plain
1frwhereminmax(0,1fr)would be safer. - Add
min-width:0to flex or grid children that contain long content. - Avoid fragile combinations of
calc(), percentage widths, borders, and fixed gaps when the layout must align perfectly. - Test common desktop widths like 1366px, 1440px, and 1920px.
- Do not hide the problem with random negative margins unless you have identified the real cause.
100vw usage with 100% and retest. margin-left:-1px without understanding why the layout moved. Final takeaway
A layout shift by 1px at certain screen widths usually comes from CSS sizing math. The most common causes are 100vw, scrollbar width, subpixel rounding, fractional Grid or Flexbox distribution, padding, borders, and breakpoint rules that change too much at once.
Start with the simple checks: avoid unnecessary 100vw, use box-sizing:border-box, stabilize your container formula, inspect breakpoints, and reduce layout pressure inside Grid and Flexbox. Once the sizing system becomes predictable, the tiny 1px shift usually disappears.
Want more fixes like this?
Explore the full FrontFixer fixes library and keep debugging with practical guides built for real front-end layout problems.