BlogDevelopment

Why Designers Should Learn CSS Grid Before Flexbox Tricks

Most layout bugs come from using flexbox for two-dimensional problems. Here's why I think designers should reach for grid first, and where flex still wins.

Denny Pratama

16 Nov 2026 · 6 min read · Development

Why Designers Should Learn CSS Grid Before Flexbox Tricks

When I design a layout in Figma, I think in rows and columns. When I started building my own designs with AI coding tools, I noticed the code often did not think that way. It reached for flexbox for almost everything, then patched the gaps with fixed widths and margins.

My opinion: if you are a designer who now ships code, learn CSS Grid first. Not because flexbox is bad, but because grid matches how designers already think, and it removes a whole class of layout bugs.

01Flexbox and grid answer different questions

The simplest framing I know:

  • Flexbox asks: "How should these items share space along one line?"
  • Grid asks: "What is the structure of this area, in rows and columns?"

Flexbox is content-first. Items size themselves, and the container distributes leftover space. Grid is layout-first. You define the tracks, then place things in them.

Most of the pain I see comes from using a one-dimensional tool for a two-dimensional problem. Say you have a row of six cards that should wrap onto a second row. With flexbox, the last row often stretches or misaligns unless you add extra rules. With grid, the columns exist whether or not the last row is full, so everything lines up.

02Why I'd learn grid first

It matches your Figma habits

Figma's layout grids and auto layout are different things, but designers are used to columns, gutters and alignment. Grid maps to that directly: columns, gap, and items placed on lines.

It reduces magic numbers

A flexbox layout that looks right at one width often relies on percentage widths, fixed basis values or margins that someone tuned by eye. Those break at the next width.

A grid like this has almost no magic in it:

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.5rem;
}

Each card is at least 16rem wide, the columns fill the space, and the number of columns changes by itself. No breakpoint needed. That one pattern covers a lot of marketing pages and dashboards.

It makes alignment a property of the layout, not the item

In grid, gap handles spacing between items, and every item in a row or column aligns to the same tracks. You are not nudging individual elements to match their neighbours. For a designer who cares about consistent spacing, that is a big deal.

03Where flexbox is still the right tool

I am not arguing for grid everywhere. Flexbox is the better fit when:

  • You have one row or column of items, such as a toolbar, a button group or a nav bar.
  • Items should size to their content, like tags or chips that wrap.
  • You need to push one item away from the rest, such as a logo on the left and links on the right, using margin-left: auto.
  • You are centring something inside a small component.

A good rule: grid for the structure of a section, flex for the contents of a cell. Nesting them is normal. A grid of cards where each card uses flex to pin its button to the bottom is a perfectly healthy layout.

04Container queries: the part that suits components

Media queries respond to the viewport. That works for page-level changes, but it is awkward for components. A card might sit in a wide main column on one page and a narrow sidebar on another, with the same viewport width in both.

Container queries let the component respond to the space it actually has:

.card-wrap {
  container-type: inline-size;
}

@container (min-width: 28rem) {
  .card {
    display: grid;
    grid-template-columns: 8rem 1fr;
  }
}

I think this fits how designers already build components in Figma, where a component is designed to adapt to its frame, not to the whole screen. You do not need to master it on day one. Just know it exists, so that when a component looks wrong in a sidebar, you can ask for the right fix instead of another breakpoint hack.

05What to check when AI builds your layout

Since I lean on AI tools for the code, my real skill here is reviewing, not writing. These are the checks I'd run:

  1. Resize slowly. Drag the browser edge instead of jumping between a few device widths. Layouts usually break between the "standard" sizes.
  2. Turn on the grid and flex overlays in your browser's dev tools. You can see immediately what the layout is built from.
  3. Look for fixed widths. Lots of width: 320px or margin-left: 37px suggests the layout is tuned to one screenshot.
  4. Check the last row. If a wrapping row of items looks stretched or misaligned, it probably should be grid.
  5. Zoom text to 200%. A layout that survives larger text is usually structurally sound. WCAG's reflow criterion expects content to work at narrow widths without two-dimensional scrolling, so this is worth testing.
  6. Check content extremes. Paste in a very long title and a very short one. Layouts built around perfect content fall apart quickly.

For a broader review routine, my checklist for reviewing AI-built UI covers more than layout. And if the problem you see is content jumping around as things load, that is a different issue, which I covered in layout shift from a designer's side.

06How to prompt for better layouts

Vague prompts get default answers, and the default is often flexbox plus fixed sizes. Be specific about structure:

  • "Use CSS Grid for the section layout and flexbox only inside cards."
  • "Use gap for spacing, not margins on children."
  • "No fixed widths on cards. Use minmax() with auto-fit."
  • "Make the card component adapt using a container query, not the viewport."

You are describing the structure the way you would describe a Figma frame. That is something designers are already good at.

07The takeaway

You do not need to become a CSS expert to ship good layouts. You need a small, correct mental model: grid for structure, flex for flow, container queries for components. With that, you can read what an AI tool produced, see where it is fragile, and ask for something better.

If I had to pick one thing to practise this week, it would be rebuilding a card grid with repeat(auto-fit, minmax(...)). It is short, it works at every width, and it shows you how much of responsive layout can be handled without a single breakpoint.

08Frequently asked questions

Should designers learn CSS Grid or Flexbox first?

I'd start with the mental model of both, then default to grid for page and section layout. Flexbox is better for a single row or column of items, like a button group or a nav bar. Knowing which question each one answers matters more than memorising properties.

Do container queries replace media queries?

No, they answer a different question. Media queries respond to the viewport, while container queries respond to the size of a component's parent. Most pages will use both, with media queries for page-level changes and container queries for reusable components.

How do I check if an AI tool built my layout sensibly?

Resize the browser slowly instead of jumping between a few device widths, and look for overlaps, orphaned items and awkward gaps. Then open the dev tools layout overlay and see whether grid or flex is being used where it fits. If you see lots of fixed widths and magic margins, ask for a rewrite.

Development

Denny Pratama

Product designer in Indonesia. Since 2018 I’ve designed SaaS products, dashboards and marketing sites, and now I build my own designs too.

About me