The Half-Pixel Problem: Why Your Grid Looks Fine on Your Mac and Falls Apart on Your Coworker's Laptop
Photo: developer inspecting website layout on laptop screen with code editor, via bairesdev.mo.cloudinary.net
You've seen it before. The QA ticket comes in with a screenshot attached: a card row that's off by a hair, a divider that doesn't quite reach the edge, a button whose right border has vanished into the padding. On your machine — a MacBook with a crisp Retina display — everything looks flawless.
That's not a coincidence. It's sub-pixel rounding, and it's one of the most common layout bugs that makes it all the way to production.
What's Actually Happening When Browsers Round
When you divide a 1000px container into three equal columns, the browser doesn't get a clean 333.33px per column — it gets a repeating decimal. Every rendering engine has to decide what to do with that leftover fraction, and they don't all decide the same way.
Blink (Chrome and Edge) historically rounded some elements up and others down to make the math balance out. WebKit (Safari) has its own rounding strategy, and Gecko (Firefox) another. On top of that, the device pixel ratio changes the math entirely: on a 1x display, one CSS pixel is one physical pixel, so a 0.33px rounding error is visible. On a 2x or 3x Retina screen, the browser has physical pixels to spare and can render fractional positions more faithfully — which is why the bug hides on designer laptops and surfaces on budget Windows monitors and older office displays.
The result is layout drift that's invisible to the person who built it and obvious to a chunk of the audience.
Where It Shows Up Most
Flexbox gaps and equal-width children. flex: 1 with a gap is the classic offender. The browser distributes leftover space, hits a fractional value, and rounds one child differently than its siblings. You get a row where the third card is 1px wider and the border on its edge lands in the wrong place.
Percentage-based grids. grid-template-columns: repeat(3, 33.333%) looks tidy in your CSS but produces fractional track sizes in practice. Content inside those tracks — especially text and borders — can shift by a pixel depending on which track it landed in.
Transforms and centered elements. translateX(-50%) on an element with an odd pixel width puts its edge on a half-pixel boundary. On 1x displays, that's blurry text and soft borders.
Viewport-relative sizing. width: 33.33vw on a 1366px viewport (still one of the most common laptop widths in the US) gives you 454.9px. Something has to give.
A Devtools Workflow That Actually Catches It
You can't eyeball this stuff on a Retina screen, so stop trying. Here's the routine:
-
Drop your device pixel ratio to 1. In Chrome DevTools, open the device toolbar, set DPR to 1, and resize to common non-Retina widths — 1366, 1440, 1920. This is where fractional errors become visible.
-
Use the layout overlay, not the screenshot. Firefox's DevTools has a genuinely useful feature here: hover a grid or flex container and it highlights the exact track sizes, fractional values included. Chrome's grid inspector shows track size deltas too.
-
Check element boundaries, not just sizes. Hover two adjacent siblings and look at their bounding boxes in the overlay. If one ends at x=455 and the next starts at x=455.33, you've found your drift.
-
Screenshot-compare across browsers. Take a full-page screenshot in Chrome, Firefox, and Safari at the same 1x viewport and diff them in any image tool. A two-minute check that catches what an hour of squinting won't.
Practical Fixes That Don't Require a Rewrite
- Let the browser handle the math.
repeat(3, 1fr)in grid, orflex: 1 1 0with a defined basis, distributes space more predictably than percentage widths. - Snap critical edges. For hairline borders and dividers, use
box-shadow: insetor a1pxpseudo-element positioned with whole-pixel values rather than relying on a fractional layout edge. - Avoid odd-width centered transforms. If an element is 99px wide,
translateX(-50%)puts it on a half-pixel. Round the element's width or use flexbox centering instead. - Test at 1x before every release. Add it to the checklist. It costs five minutes and catches the class of bug that otherwise surfaces as a "looks slightly off" ticket three weeks after launch.
The Bottom Line
Sub-pixel rounding isn't a browser bug you can file — it's a consequence of asking engines to divide space in ways that don't divide evenly. The designers and developers who ship clean layouts aren't the ones avoiding fractional values entirely; they're the ones who know their layout will be inspected on a 1x display and have a workflow ready when it is.
Your Mac is lying to you, just a little, every day. Build for the laptop in the break room instead.