VOOZH about

URL: https://blog.logrocket.com/using-chrome-devtools-to-debug-css-grid/

โ‡ฑ Debug CSS Grid with Chrome DevTools - LogRocket Blog


2021-01-04
1784
#chrome#css
Rob O'Leary
31137
๐Ÿ‘ Image

See how LogRocket's Galileo AI surfaces the most severe issues for you

No signup required

Check it out

CSS Grid is a powerful layout specification that is growing in popularity year by year. This yearโ€™s State of CSS Survey showed that 73.3% of respondents have used Grid, an increase of 18.6% from 2019.

๐Ÿ‘ Chrome devtools css grid debug
๐Ÿ‘ State of CSS Grid usage
Thereโ€™s been a sharp increase in CSS grid usage.

An important part of Gridโ€™s success story is that now most of the major browsers have added Grid support to their DevTools. Visual inspection gives you a more efficient feedback loop when youโ€™re building out an interface.

It can take some of the pain out of debugging layout issues: no more adding red borders (or some similar hack) to see what is going on when you are building out your layouts.

In this article, Iโ€™ll focus on Chrome. I will show you how to discover grids in a page and give you tips on how to inspect the page layout and debug layout issues.

๐Ÿš€ Sign up for The Replay newsletter

The Replay is a weekly newsletter for dev and engineering leaders.

Delivered once a week, it's your curated guide to the most important conversations around frontend dev, emerging AI tools, and the state of modern software.

Discovering grids in a page with Chrome DevTools

First things, first. What makes an HTML element a grid?

If an HTML element on your page has display: grid or display: inline-grid applied to it, itโ€™s a grid.

You may need to enable Grid debugging in the DevTools settings, as it is still considered an experimental setting:

๐Ÿ‘ Enable grid in Chrome Devtools

You can quickly discover if a page has grid elements in the following ways.

1. Discovery by inspection

In the Elements pane, you will see a grey grid badge next to a grid element:

๐Ÿ‘ Chrome DevTools CSS find grids

In this simple example, the div with the โ€œwrapperโ€ class is a grid.

Clicking this badge will toggle the display of an overlay for the element, like so:

๐Ÿ‘ Chrome Devtoools enable CSS grid overlay

You will see the badge has changed color to indicate that is now active.

The overlay shows:

  • Numbered grid lines
  • Gaps between grid items are shown as a gutter with a dashed pattern. The gap is 10px in our case, which is easy to pick out. Of course, you may not have a gap, and there will be no gutter. Instead, you will see grid items flush to each other (as below)

๐Ÿ‘ Chrome devtools css grid no gaps

2. Discovery by overview

In a more complex web page, there may be many grids, and they may not be a child of body like our previous example. It is more work to find them by inspection if you want to understand the layout of a page.

The Layout pane has a Grid section, which lists all of the grids out for us.

Letโ€™s take another example, recreating Instagramโ€™s profile page using Grid. Notice it has eight grids. You can see them listed under the subheading โ€œGrid overlaysโ€ (see red box below).

๐Ÿ‘ chrome devtools css grid layout pane

The grids are listed in order of occurrence. The label comprises the element name, ID selector (if any), and class selectors (if any).

You can show the overlay by checking the adjacent checkbox:

๐Ÿ‘ chrome devtools CCS grid select overlay

As you can see, there are some other settings in the Layout pane, which we will cover next.

Customizing the overlay in Chrome

There are some options for customizing the overlay in the Layout pane. Letโ€™s cover the Grid overlays section first.

Grid overlays section

๐Ÿ‘ chrome devtools css grid overlay options

Chrome selects different colors for the overlays by default to make it easy to distinguish between them. There is an adjacent color picker if you want to choose your own. This is especially useful if there is a clash between the grid overlay color and the background.


Over 200k developers use LogRocket to create better digital experiences

๐Ÿ‘ Image
Learn more โ†’

The second option in this section will highlight the overlay for the element in the webpage, and select the element in the Elements pane (as below). This doesnโ€™t customize the overlay; rather, it helps orientate you and explores the associated styles.

๐Ÿ‘ select element

Overlays display settings

It should be fairly clear what these display settings are, but letโ€™s go through each one to discuss the finer points.

๐Ÿ‘ chrome devtools css grid overlay display settings

1. Show track sizes setting

The show track sizes setting is useful for understanding why a grid item ends up as particular size.

To get the terminology straight, letโ€™s define a track.

According to CSS Grid Layout Module Level 1 by W3C, a grid track is a generic term for a grid column or grid row โ€” in other words, it is the space between two adjacent grid lines. Each grid track is assigned a sizing function, which controls how wide or tall the column or row may grow, and thus how far apart its bounding grid lines are.

In this context, it is just telling you the width and height of a grid item, which may span multiple rows or columns.

The track size label has the following format: [authored size] - [computed size]. The authored size is the size declared in the stylesheet (it is omitted if nothing is defined). The computed size is the actual size on the screen.

Letโ€™s return to our Instagram example to illustrate this.

You can see that the story section has a fixed width of 115px.

๐Ÿ‘ Chrome devtools css grid track size story

.story {
 display: grid;
 grid-template-columns: repeat(auto-fill, 115px);
}

Because the size is fixed, the columnโ€™s authored size and the actual size are the same.

The row label only shows the actual size because we have nothing declared for that track.

For the posts section, the column width is a range.

๐Ÿ‘ chrome devtools css grid track size gallery

.tabbed-pane__posts {
 display: grid;
 grid-template-columns: repeat(3, minmax(50px, 1fr));
 grid-gap: 25px;
}

The authored size is minmax(50px, 1fr) and the actual size is 236px for this viewport size. The actual size will vary depending on the viewport width.

Again, the row label only shows the actual size because there is nothing defined for it.

2. Show area names setting

If you have named areas on your grid, this setting will show them as inset label in the top-left corner of each item.

In this example, we name three areas: header, sidebar, and content. We assign areas to tracks using grid-template-areas.

We have left the first grid item empty, so it does not have a label.

๐Ÿ‘ chrome devtools css grid area names

<div class="wrapper">
 <div class="box header">Header</div>
 <div class="box sidebar">Sidebar</div>
 <div class="box content">Content</div>
</div>
.sidebar {
 grid-area: sidebar;
}

.content {
 grid-area: content;
}

.header {
 grid-area: header;
}

.wrapper {
 display: grid;
 grid-gap: 10px;
 grid-template-columns: 120px 120px 120px;
 grid-template-areas:
 "....... header header"
 "sidebar content content";
}

3. Extend grid lines setting

The extend grid lines setting is useful if you want to align independent elements. It creates dashed lines that extend beyond the boundaries of the grid.

In our Instagram example, if we wanted to align the header and the story sections in some way, the extended grid lines can act as guidelines.

๐Ÿ‘ chrome devtools css grid extend grid lines

Debugging tips using Chrome DevTools

You can make your grids easier to identify by adding an ID or class to the element, or by using area names.

In our Instagram example, initially we had three ul elements that are grids but no IDs or classes (see red box). So, we canโ€™t distinguish between them.

๐Ÿ‘ chrome devtools css grid ul grids

Adding the classes to the ul makes them more identifiable!

๐Ÿ‘ chrome devtools ul grid classes

This may sound trite, but prevention is better than cure. Some issues can be avoided by planning a layout out first. The power of a grid is that it is easier to impose order, so why not decide on what youโ€™re doing before you do it?

Your design doesnโ€™t have to be very detailed, something like the design below is usually enough:

๐Ÿ‘ chrome devtools css grid design
Layout example. Source: CSS Grid Layout Module Level 1 Specification.

The important part is that you consider element sizes, alignment, and spacing of your layout in advance. You need to design for different device sizes and decide how you present the content within the available space. You may need to wrap items or change the grid layout for different device sizes.

I donโ€™t want to prescriptively itemize how to debug layouts โ€” there are far too many permutations. Instead, I will discuss a couple of design decisions from our Instagram example. This will give you some ideas about how you can review and resolve issues.

Most common causes of bugs

The sizing of tracks and content is probably the most common cause of issues.

If you set a fixed size for a track, you should ensure that the content does not overflow (unless you decide you want it to, of course). To deal with overflow, you can: set a fixed size for the content; use the overflow property; or the object-fit property for images and videos.

For example, the story section in our Instagram example has a fixed column size of 115px on mobile devices.

๐Ÿ‘ chrome devtools css grid track size story

We fix the size of the image to 56px. For the heading (h2) below the image, we hide content that overflows and prohibit text wrapping (so it is always a single line of text). Adding text-overflow:ellipsis; appends ellipses to the end of the text to indicate that the text is truncated.

Now, we can guarantee that every โ€œstoryโ€ is uniform in size. When you are dealing with dynamic content, you need to anticipate this happening:

.story img {
 border-radius: 50%;
 width: 56px;
 height: 56px;
}

.story h2 {
 overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;
}

If we didnโ€™t manage the overflow of the heading, it would look like this:

๐Ÿ‘ Chrome DevTools css grid story no overflow

The other part of sizing is the units you use. You should only choose fr or minmax() when you are happy for the size of an item to be dynamic. Use other values if you want to freeze their size.

๐Ÿ‘ chrome devtools css grid header

Take the header section for example. The first column (track) has a width of one fractional unit (1fr). This will grow when there is more available space. It doesnโ€™t cause any shifting or resizing of the logo image (.header__logo) because its size is absolute, and itโ€™s positioned at the start of the item.

Keep in mind that if you have content with a min-width or min-height declared, you can have unexpected results with the fractional unit.

The fr unit fills up the available space but it is never smaller than the minimum size of the grid container or the content of the row or column:

header {
 display: grid;
 grid-template-columns: 1fr auto auto;
 align-items: center;
 width: 100%;
}

.header__logo {
 justify-self: start;
}

The other two grid items (the Login and Sign Up buttons) will always remain the same size.

When troubleshooting, it can be useful to resize the viewport to see how the size of grid items vary. In our example, you can clearly see that it is only the first item that changes size.

๐Ÿ‘ chrome devtools CSS grids resizing header

Conclusion

With the addition of Grid support to Chrome DevTools, you can now easily visualize and debug your layout. Getting better feedback while you build layout is a big boost for productivity. I hope this article was able to show you how you can benefit from using the Chrome DevTools when working with CSS Grid.

Is your frontend hogging your users' CPU?

As web frontends get increasingly complex, resource-greedy features demand more and more from the browser. If youโ€™re interested in monitoring and tracking client-side CPU usage, memory usage, and more for all of your users in production, try LogRocket.

๐Ÿ‘ LogRocket Dashboard Free Trial Banner

LogRocket lets you replay user sessions, eliminating guesswork around why bugs happen by showing exactly what users experienced. It captures console logs, errors, network requests, and pixel-perfect DOM recordings โ€” compatible with all frameworks.

LogRocket's Galileo AI watches sessions for you, instantly identifying and explaining user struggles with automated monitoring of your entire product experience.

Modernize how you debug web and mobile apps โ€” start monitoring for free.

๐Ÿ‘ Image
๐Ÿ‘ Image
๐Ÿ‘ Image

Stop guessing about your digital experience with LogRocket

Get started for free

Recent posts:

What is TSRX?: What JSX would look like if it were designed today

TSRX adds first-class control flow, conditional hooks, and scoped styles to React via a TypeScript compiler extension โ€” no new framework required.

๐Ÿ‘ Image
Ikeh Akinyemi
Jun 12, 2026 โ‹… 6 min read

How to add authentication to a React Native app with Better Auth

Learn how to build a full React Native auth system using Better Auth and Expo โ€” with email/password login, Google OAuth, session persistence, and protected routes.

๐Ÿ‘ Image
Chinwike Maduabuchi
Jun 9, 2026 โ‹… 13 min read

AI dev tool power rankings & comparison [June 2026]

Compare the top AI development tools and models of June 2026. View updated rankings, feature breakdowns, and find the best fit for you.

๐Ÿ‘ Image
Chizaram Ken
Jun 8, 2026 โ‹… 11 min read

How to check username availability at scale with Bloom filters

Learn how Bloom filters reduce database lookups for username availability checks while preserving correctness at scale.

๐Ÿ‘ Image
Rosario De Chiara
Jun 8, 2026 โ‹… 6 min read
View all posts

Would you be interested in joining LogRocket's developer community?

Join LogRocketโ€™s Content Advisory Board. Youโ€™ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now