Inspecting layout with DevTools

Topic 3 of 3 in Getting started7 min readBeginnerFree course

Overview

Layout bugs are hard to fix when you can’t see the boxes. Every modern browser ships developer tools (DevTools) that make layout visible: box sizes, spacing, grid lines, flex free space, and even explanations of why a property isn’t working. Learning them early will save you hours. The examples use Chrome and Edge; Firefox and Safari have equivalent tools, and Firefox’s grid and flex inspectors are especially good.

Open DevTools with right-click → Inspect, or F12 / Ctrl+Shift+I (Cmd+Option+I on macOS).

Layout tools in browser DevTools: a page with a grid overlay showing dashed tracks and numbered grid lines. Elements panel badges — click grid or flex for overlays. Computed tab box model — margin, border, padding and content sizes. Layout panel — overlay options and line numbers. Hover an element to see its size and spacing highlighted.

Highlighting boxes

In the Elements panel, hover any element in the tree. The page highlights its box in colours that match the box model:

  • blue — content,
  • green — padding,
  • yellow — border,
  • orange — margin.

A tooltip shows the element’s rendered size, like div.card 392 × 180. Use the select tool (the arrow icon, or Ctrl+Shift+C) to click an element on the page and jump to it in the tree.

The box model diagram

Select an element and open the Computed tab. At the top is a diagram of its margin, border, padding and content with the exact pixel values. When an element is “a bit too wide”, this tells you instantly whether padding, border or margin is responsible.

Below the diagram, Computed lists every property’s final value — after the cascade, inheritance and unit conversion. If you wrote width: 50%, Computed shows the pixels it resolved to.

Grid and flex overlays

In the Elements tree, flex and grid containers show small flex and grid badges. Click one to draw an overlay on the page:

  • Grid overlays show tracks, gaps, line numbers, area names and the size of each track.
  • Flex overlays show the container, items, gaps and the free space the algorithm is distributing.

The Layout panel (next to Styles and Computed) lists every grid and flex container on the page and lets you choose colours and turn on line numbers, track sizes and area names. Leave overlays on while you work on a layout — seeing the tracks makes grid placement obvious.

Chrome also shows editor buttons next to display: flex and display: grid in the Styles pane. They open a visual picker for properties like justify-content and align-items, with icons showing what each value does.

Why isn’t my property working?

In the Styles pane, look at how declarations are displayed:

  • Crossed out — overridden by a more specific or later rule. Find the winner above it.
  • Warning icon / crossed out with a yellow triangle — invalid value or unknown property: a typo, or an unsupported feature.
  • Greyed out with an ⓘ icon — inactive: valid, but it has no effect in this context. Hover the icon for an explanation: for justify-content on a plain block, DevTools explains that the element’s display value prevents it from having an effect, and suggests switching to flex or grid.

Inactive properties are the most common layout confusion: justify-content on a non-flex element, width on an inline element, z-index on a non-positioned element, flex-grow on something whose parent isn’t a flex container. DevTools tells you directly.

Live editing

Everything in the Styles pane is editable:

  • click a value to change it, and use the ↑/↓ arrow keys to nudge numbers (Shift for ×10),
  • untick a checkbox to toggle a declaration off and see what it was doing,
  • click the + button to add a new rule,
  • Ctrl+Z undoes changes.

Edits are temporary — copy working values back into your stylesheet. (Chrome’s Changes tab lists everything you modified.)

Testing other screen sizes

The device toolbar (Ctrl+Shift+M) resizes the viewport to phone and tablet sizes, or any width you type. Drag the edge to watch your layout respond. Responsive mode also emulates touch, device pixel ratio and slow networks. It’s an approximation — always check real devices before launching — but it catches most problems.

Other useful tools

  • Rendering → Show layout shift regions highlights content that jumps as the page loads.
  • Elements → right-click → Force state shows :hover and :focus styles while you inspect them.
  • CSS Overview (Chrome) summarises colours, fonts and unused declarations across the page.
  • In the Console, $0 refers to the currently selected element: $0.getBoundingClientRect() gives its exact position and size.

Habit to build: when a layout surprises you, don’t guess — inspect. Find the box, read its computed size, check its parent’s layout mode, and look for crossed-out or greyed-out properties.

Exercise

Investigate a broken card

Paste this page into a file and open it. The card is meant to be 20rem wide with its text centred, but it overflows on narrow screens and the text isn’t centred. Use DevTools to answer: (1) what is the card’s rendered width and why? (2) why does justify-content: center show as inactive? Then fix the CSS so the card is at most 20rem wide, never wider than the screen, and its text is centred.

HTML
<div class="card">
  <h2>Responsive layouts</h2>
  <p>Learn flexbox and grid.</p>
</div>

<style>
  .card {
    width: 20rem;
    padding: 2rem;
    border: 4px solid #2d5bd7;
    justify-content: center;
  }
</style>

Summary

  • Right-click → Inspect opens the Elements panel; hovering an element highlights its content, padding, border and margin.
  • The Computed tab’s box-model diagram shows each box’s real sizes.
  • Grid and flex badges in the Elements panel toggle overlays showing tracks, lines, gaps and free space.
  • DevTools greys out properties that have no effect and explains why when you hover the info icon.
  • Edit values live, toggle properties on and off, and use the device toolbar to test other screen sizes.