Overview
Build card grids and 12-column systems that collapse cleanly.
Responsive Grid Patterns focuses on two-dimensional layout. Grid is strongest when rows and columns both matter, especially when you want explicit placement, named areas, or repeatable responsive tracks.
Core Ideas
- Use Responsive Grid Patterns when rows and columns both shape the design.
- Define tracks with repeat, minmax, fr units, or named lines.
- Let auto-placement help, but explicitly place important regions.
- Check how the grid behaves when content becomes longer than expected.
Step by Step
- Set display: grid on the layout parent for Responsive Grid Patterns.
- Define columns, rows, and gaps before placing individual items.
- Use grid-area, grid-column, or grid-row for intentional placement.
- Test extra content so implicit tracks do not surprise you.
Beginner Explanation
Responsive Grid Patterns shows how Grid adapts to small and large screens.
Responsive Grid often starts with one column, then adds flexible tracks as space becomes available.
auto-fit, minmax, fr units, and media queries are the main tools for beginner-friendly responsive grids.
Before You Start
- Before practicing Responsive Grid Patterns, decide which element should be the grid container.
- Count the columns and rows the design needs before writing CSS.
- Decide whether auto-placement is enough or whether important items need explicit placement.
- Prepare extra content so you can test how the grid behaves when the layout is not perfect.
Key Grid Properties
- repeat(auto-fit, minmax(...)) creates flexible card grids.
- Media queries can change grid areas or column counts.
- 1fr shares available space after fixed tracks are counted.
- gap creates consistent spacing between rows and columns.
Plain-English Glossary
- Grid container: the parent element with display: grid.
- Grid item: a direct child of the grid container.
- Track: one row or column.
- Grid line: the boundary between tracks.
- Grid area: a rectangular group of cells.
- Implicit grid: rows or columns created automatically when content does not fit the explicit grid.
What You Will Learn
- Explain which tracks, lines, or areas Responsive Grid Patterns creates.
- Predict where a new grid item will be placed.
- Use browser developer tools to inspect the grid overlay.
- Change one grid property in the editor and explain how the layout reacts.
Where You Use This in Real Projects
You use Responsive Grid Patterns in dashboards, article layouts, galleries, product grids, admin screens, pricing sections, forms, and app shells.
Grid is especially useful when rows and columns both matter, or when the layout needs named regions that stay readable in CSS.
Browser and Accessibility Notes
- Visual placement should not make the reading order confusing.
- Avoid dense placement when it makes keyboard or source order hard to follow.
- Test small screens, long text, zoom, and extra items so implicit tracks do not surprise you.
- Grid changes layout, not document meaning, so start with semantic HTML and ordered headings.
Code Example
.row {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 1.5rem;
}
.col-8 { grid-column: span 8; }
.col-4 { grid-column: span 4; }
@media (max-width: 760px) {
.col-8, .col-4 { grid-column: 1 / -1; }
}
Another Example
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
gap: 1rem;
}
More Practice Examples
Example 1: Responsive card grid
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
gap: 1rem;
}
.card--featured {
grid-column: span 2;
}
- auto-fit creates as many columns as fit in the available space.
- minmax keeps cards from becoming too small while still allowing them to grow.
- A featured item can span more columns, but you should test narrow screens.
Example 2: Page shell with named areas
.shell {
display: grid;
grid-template-areas:
"top top"
"nav content";
grid-template-columns: 16rem 1fr;
gap: 1rem;
}
.top { grid-area: top; }
.nav { grid-area: nav; }
.content { grid-area: content; }
- Named areas make the layout easy to read.
- The template rows describe the visual page shell.
- Area names must match the grid-area values on children.
Example 3: Auto-placement gallery
.gallery {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 7rem;
grid-auto-flow: dense;
gap: .75rem;
}
.gallery__wide { grid-column: span 2; }
.gallery__tall { grid-row: span 2; }
- The explicit columns are fixed, while rows can be created automatically.
- span makes some items larger without manually placing each one.
- dense can fill gaps visually, so check that reading order still makes sense.
Example Explained
- The Responsive Grid Patterns example starts by choosing the grid container.
- The template properties define the explicit rows, columns, or named areas.
- Direct children become grid items and can be auto-placed or explicitly placed.
- The gap property creates consistent spacing without extra wrapper elements.
How to Read This Example
- Find display: grid and name the grid container.
- Read grid-template-columns, grid-template-rows, or grid-template-areas before looking at item placement.
- Identify which items are auto-placed and which items are manually positioned.
- Change one track, span, area, or gap in the Responsive Grid Patterns example and resize the preview.
Code Editor Example
Open a ready-made starter for this lesson in the live HTML, CSS, and JavaScript editor. You can change the code, then click Run to see the result immediately.
Open in Code EditorChecklist
- Name important areas or lines when it improves readability.
- Use minmax and auto-fit/auto-fill for resilient responsive grids.
- Check how implicit rows and columns are created.
Common Mistakes
- Overplacing every item when auto-placement would be simpler.
- Forgetting that content can create implicit tracks.
- Using fixed columns where minmax or fr units would respond better.
Do and Don't
- Do: use Responsive Grid Patterns when rows and columns both matter.
- Do: use gap for spacing and minmax/fr units for flexible tracks.
- Don't: use Grid only to center one row of buttons when Flexbox would be simpler.
- Don't: use dense placement if it makes visual order disagree with meaningful source order.
Practice Challenge
Turn the Responsive Grid Patterns example into a small page section, then add one extra item and predict where Grid will place it.
Try These Changes
- Change one column from 1fr to minmax(12rem, 1fr) and explain the difference.
- Add one extra grid item and predict where auto-placement will put it.
- Make one item span two columns, then test the narrow viewport result.
- Turn on the browser grid overlay and identify lines, tracks, gaps, and areas.
Quick Check
- Question: What creates a grid container? Answer: display: grid or display: inline-grid.
- Question: What is a track? Answer: One grid row or column.
- Question: What does 1fr mean? Answer: One share of available free space.
- Question: Which elements become grid items? Answer: Direct children of the grid container.
Debugging Checks
- Confirm display: grid is on the parent element.
- Use browser grid overlays to inspect tracks, line numbers, gaps, and areas.
- Check for misspelled area names and non-rectangular grid-template-areas.
- Check implicit rows or columns when items appear outside the expected layout.
Mini Project
Build a responsive product or lesson card grid for Responsive Grid Patterns: use repeat, auto-fit, minmax, gap, and one featured card that changes span on small screens.
Mastery Check
- You can describe the tracks used by the Responsive Grid Patterns layout.
- You can place one item explicitly and let another auto-place.
- You can make the grid adapt when content or viewport size changes.