WEMAXA.COM Design · Development · AI · Available worldwide
Studio / Wemaxa 01
Status Active Location Worldwide Focus Web + AI Delivery Remote Response < 1 Business Day
Tutorial 037Web Design & Development13 steps3 fixes

How to Create a Responsive Layout With CSS Grid

A click-and-code beginner guide to making cards/columns automatically reflow with CSS Grid.

By the end: You will build a grid that grows from one column to multiple columns without fixed device-specific widths.

TARGET RESULTHow to Create a Responsive Layout With CSS Grid

You will build a grid that grows from one column to multiple columns without fixed device-specific widths.

Key terms before you start

These definitions make the steps easier to follow and help distinguish controls, files and concepts that can look similar at first.

HTMLHyperText Markup Language; it describes the structure and meaning of web content.
CSSCascading Style Sheets; it controls presentation such as layout, spacing, color and responsive behavior.
CSS selectorThe part of a CSS rule that chooses the elements to style.
CSS propertyA named presentation setting such as display, gap, color, padding or width.
CSS GridA two-dimensional CSS layout system using rows and columns.
BreakpointA condition, commonly a viewport width, where a media query changes the layout.
Browser Developer ToolsBuilt-in browser tools for inspecting HTML/CSS, network requests, responsive layouts and console errors.

What you need before starting

  • A code editor
  • A local/staging web page you are allowed to edit
  • A modern browser with Developer Tools

Real-world notes from public discussions

These are tied to public discussions, not invented case studies. Open the source to read the full thread and surrounding replies.

Stack Overflow — responsive Grid with auto-fit/minmaxOpen discussion ↗

A practical responsive-card answer uses repeat(auto-fit, minmax(..., 1fr)) so cards wrap as available width changes instead of relying on fixed percentage columns.

How it changes this tutorial: Grid examples use this pattern where it matches the task and then test the narrowest container for overflow.
FULL TUTORIAL

Step-by-step tutorial

Every step is shown below. Work through them in order and use each checkpoint to confirm the result before moving on.

01
STEP 01 / 13

Work on a local or staging copy

Do this

Open the project containing the HTML/CSS source. If this is a production site, use a staging copy or backup before structural changes.

Why

A browser page is rendered from source files/CMS output; DevTools edits do not save back to the server.

HTMLHyperText Markup Language; it describes the structure and meaning of web content.
IF THIS GOES WRONGDevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

CHECKPOINTYou know which source file/template controls the page.
02
STEP 02 / 13

Open the page in a modern browser

Do this

Load the page, then press F12 or Ctrl+Shift+I (Windows/Linux) to open Developer Tools.

Why

DevTools lets you inspect the DOM, applied CSS, computed sizes, requests and console errors.

Browser Developer ToolsBuilt-in browser tools for inspecting HTML/CSS, network requests, responsive layouts and console errors.
IF THIS GOES WRONGA CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

CHECKPOINTDevTools is open beside the page.
03
STEP 03 / 13

Identify the parent and children

Do this

Wrap repeated items in one parent such as <div class="cards"> and give each item class="card".

Why

Grid layout is applied to the parent; its direct children become grid items.

CSSCascading Style Sheets; it controls presentation such as layout, spacing, color and responsive behavior.
CHECKPOINTDevTools shows cards as direct children.
04
STEP 04 / 13

Turn the parent into a grid

Do this

Add .cards { display:grid; }.

Why

display:grid creates a grid formatting context; it does not create useful columns until tracks are defined.

CSS GridA two-dimensional CSS layout system using rows and columns.
IF THIS GOES WRONGA CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

CHECKPOINTDevTools Grid badge appears in supporting browsers.
05
STEP 05 / 13

Add the column rule

Do this

Use grid-template-columns:repeat(auto-fit,minmax(16rem,1fr));.

Why

minmax sets a minimum item track size and 1fr shares remaining space; auto-fit creates as many tracks as fit.

CSS selectorThe part of a CSS rule that chooses the elements to style.
IF THIS GOES WRONGA CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

CHECKPOINTCards reflow as viewport width changes.
06
STEP 06 / 13

Add gap

Do this

Use gap:1rem on the grid parent.

Why

Gap creates spacing between tracks without edge-margin hacks.

CSSCascading Style Sheets; it controls presentation such as layout, spacing, color and responsive behavior.
CHECKPOINTSpacing is consistent between rows/columns.
07
STEP 07 / 13

Prevent content from forcing overflow

Do this

Set min-width:0 on grid items when long content/children otherwise force tracks wider.

Why

Some content has intrinsic minimum sizes that can cause overflow.

HTMLHyperText Markup Language; it describes the structure and meaning of web content.
IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTLong text/code can shrink within the track.
08
STEP 08 / 13

Choose a deliberate max container width

Do this

If appropriate, wrap the grid in a container with width:min(...,100%) and auto margins.

Why

Do not make every grid span the entire monitor simply because Grid can.

CSS propertyA named presentation setting such as display, gap, color, padding or width.
CHECKPOINTLine lengths/card widths remain usable.
09
STEP 09 / 13

Add an explicit breakpoint only when needed

Do this

If a design needs a special layout at a specific content failure point, add @media (min-width:...).

Why

Do not add 5 breakpoints before seeing a failure.

BreakpointA condition, commonly a viewport width, where a media query changes the layout.
IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTThe special layout starts where content has room.
10
STEP 10 / 13

Use Grid overlay

Do this

In DevTools Elements/Layout, enable the grid overlay when available.

Why

The overlay shows actual track lines and gaps.

CSS GridA two-dimensional CSS layout system using rows and columns.
IF THIS GOES WRONGDevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

CHECKPOINTTracks match the intended layout.
11
STEP 11 / 13

Test one, two and many cards

Do this

Temporarily test different item counts and long titles.

Why

A robust grid should not require the exact demo content count.

HTMLHyperText Markup Language; it describes the structure and meaning of web content.
IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTLast rows and long content remain acceptable.
12
STEP 12 / 13

Test the public/staging URL logged out

Do this

Open the final URL in a private/incognito window.

Why

CMS/admin sessions can hide caching, permission or styling differences.

IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTThe visitor view matches the intended result.
13
STEP 13 / 13

Document the changed file/rule

Do this

Record the file/template/component and purpose of the change in the project notes or version-control commit.

Why

Future maintainers should not have to reverse-engineer why a rule exists.

CSS selectorThe part of a CSS rule that chooses the elements to style.
IF THIS GOES WRONGDevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

CHECKPOINTThe change has a traceable reason/location.
CONCRETE EXAMPLERule

Test the rendered page, not only the source code.

Concrete examples

RuleTest the rendered page, not only the source code.

Copyable example

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

.card {
  min-width: 0;
  padding: 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
}

Troubleshooting

DevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

The page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

A CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

FINAL CHECKDocument the changed file/rule

The change has a traceable reason/location.

Documentation and references

Use these primary and supporting sources to verify current controls, browser behavior and product-specific details.