CSS layout bugs often involve invisible constraints. An element is wider than expected, items are misaligned by a few pixels, overflow appears on mobile but not on desktop, or a sticky header stops sticking after a certain scroll depth. The problem is usually one of a small set of known behaviors, but finding it requires looking at the right thing in the right tool.
Chrome DevTools has specific panels and features for debugging Flexbox and Grid layouts that most developers underuse. This guide walks through the workflow for diagnosing common layout problems.
Step 1: Open the Elements Panel and Inspect the Problem Element
Right-click the misbehaving element and select Inspect. Chrome DevTools opens the Elements panel with that element highlighted in the DOM tree. The right panel shows the Styles pane, which lists all CSS rules applied to the element, including inherited styles and browser defaults.
The first thing to look for is which declarations are being overridden. Overridden declarations appear with a strikethrough. When a value is not what you set, it is usually because a more specific rule is overriding it or an inherited value is taking precedence.
The computed tab next to Styles shows the final resolved value for every CSS property on the element, including properties you did not set. When width looks different from what you specified, the Computed tab shows you the actual pixel value the browser resolved.
Mozilla Developer Network at developer.mozilla.org documents browser default stylesheets and inheritance behavior, which helps identify where unexpected values are coming from.
Step 2: Enable the Flexbox Overlay
When a flex container is selected in the Elements panel, Chrome shows a small "flex" badge next to the element in the DOM tree. Click that badge to toggle the Flexbox overlay, which draws colored overlays on the flex container and its children showing the main axis, cross axis, and the space each item occupies.
This overlay makes immediately visible things that are invisible in the rendered output:
- Which items have grown beyond their content size
- Where the gap between items is coming from
- Whether items are overflowing their container
- How the cross-axis alignment is being applied
The overlay also shows when flex-basis is creating unexpected sizing. If an item is wider than expected, the overlay shows whether it is growing from a flex-basis value or from content.
CSS Tricks at css-tricks.com has documented the Flexbox overlay workflow in Chrome DevTools specifically, with screenshots showing what the different overlay indicators mean.
Step 3: Enable the Grid Overlay
For CSS Grid containers, Chrome DevTools provides an even more capable overlay. In the Layout panel on the right side of DevTools, there is a Grid section that lists all Grid containers on the page. Check the box next to any container to enable its overlay.
The Grid overlay shows:
- Grid track lines with their line numbers
- Track sizes in pixels
- Named grid areas if defined
- Item placement within the grid
When an item is placed in an unexpected grid cell, the overlay shows exactly which tracks it spans and what the track sizes are. This is essential for debugging grid placement issues, especially when grid-column or grid-row values are not producing the expected result.
The overlay also distinguishes between explicit tracks, those you defined in grid-template-columns, and implicit tracks, those the browser created automatically to accommodate items that went beyond the defined grid.

Photo by Daniil Komov on Pexels
Step 4: Check the Box Model
Below the Styles pane in DevTools, the Box Model diagram shows the computed values for content, padding, border, and margin for the selected element. Hover over each region to highlight it on the page.
Unexpected spacing between elements is often caused by margin collapsing, inherited margins, or browser default styles on elements like p, h1, or ul. The Box Model diagram shows all four spacing values at once, which is faster than reading through the Styles pane.
For layout problems where elements are not touching when they should be, or where a gap appears that does not come from a gap or margin declaration, the Box Model diagram is the place to look.
Step 5: Toggle Properties to Test Hypotheses
The Styles pane in DevTools lets you toggle declarations on and off by clicking the checkbox next to them. You can also edit values directly in the pane and see the result immediately on the page.
For layout debugging, this is more efficient than editing source files and refreshing. The workflow for a typical layout bug:
- Identify the element with the problem (Step 1).
- Toggle
flex-wrapon the parent to see if wrapping is causing unexpected behavior. - Change
align-itemsvalues to see what the cross-axis alignment should be. - Temporarily add
border: 1px solid redto the element to make its boundaries visible. - Toggle
min-width: 0on a flex child to see if content-based minimum sizing is causing overflow.
The changes are not saved to your source files, so you can experiment freely and then implement only the changes that solve the problem.
Google's web.dev platform has a DevTools CSS debugging guide that covers the overlay features and inspection workflow in detail, with step-by-step instructions for common debugging scenarios.
Step 6: Check the Device Emulation for Responsive Issues
Most layout bugs that only appear on mobile are caused by the viewport width being smaller than a flex item's content, a min-width constraint not handled at narrow widths, or a missing overflow: hidden on a container. Device emulation in DevTools, accessible via the device toolbar at the top of DevTools, lets you test these without a physical device.
The W3C at w3.org maintains the viewport specification that governs how browsers interpret the viewport meta tag. If responsive behavior is inconsistent across devices, checking the viewport meta tag in the page source is a good starting point.

Photo by Jakub Zerdzicki on Pexels
Common Layout Bugs and What They Look Like in DevTools
Items overflowing their container: The item's computed width exceeds its parent in the Box Model view. Usually caused by min-width: auto on a flex child or a fixed width that does not account for padding.
Misaligned items in a flex row: The Flexbox overlay shows some items on a different baseline. Usually caused by align-items defaulting to stretch when you expected center, or by an item having a different height due to different content.
Grid item in the wrong cell: The Grid overlay shows the item in a cell that does not match your grid-column declaration. Often caused by a grid line numbering confusion: negative line numbers count from the end, and explicit line names may not match your mental model.
Sticky element stops sticking: The element has a parent with overflow: hidden or overflow: auto, which creates a new scroll container. position: sticky sticks relative to its scrolling ancestor, not the viewport. Check the parent hierarchy for overflow declarations using the Styles pane.
Putting It Together
DevTools reduces CSS debugging from guessing to verifying. The Flexbox overlay, Grid overlay, and Box Model diagram give you the actual values the browser is using, not what you wrote, which is where most layout bugs live: in the gap between intended and computed values.
The CSS layout patterns in these CSS patterns include common patterns for centering, responsive grids, and sidebar layouts. Understanding how to inspect them in DevTools makes it easier to adapt each pattern when your content or constraints differ from the examples. 137Foundry applies this debugging workflow in frontend development for client projects, typically diagnosing layout issues in minutes rather than hours.
Top comments (0)