Search pages

Search all CSS Showcase pages by name

CSS Grid

The ultimate two-dimensional layout system — precise control meets flexibility

Grid Fundamentals

CSS Grid allows you to create complex layouts by defining rows and columns, then placing items exactly where you want them.

Basic Grid
1
2
3
4
5
6

repeat(3, 1fr)

css
Responsive Grid
1
2
3
4
5

auto-fit, minmax(120px, 1fr)

css
Mixed Column Widths
150px
1fr (flexible)
100px

150px 1fr 100px

css
Gap Property
1
2
3
4

gap: 2rem

css

Grid Placement

Place items precisely using line numbers, spanning, and the grid-column/grid-row properties.

Spanning Rows & Columns
Span 2 cols
Span 2 rows
Normal
Normal
Full Width (1 / -1)
css

Grid Template Areas

Define your layout visually using named grid areas — it's like ASCII art for layouts!

Named Grid Areas
Header
Main Content
Footer
css

Real-World Grid Layouts

Practical grid layouts you can use in your projects today.

Masonry-like Layout
Tall
Normal
Wide
Normal
Tall
Normal
Big
Normal
css
Dashboard Layout
Stats Panel
Chart Area
Users
Alerts
Revenue
Activity Feed
css
Magazine Layout
Feature Article
Article 2
Article 3
Sidebar
Related Stories
Ad Space
css

Interactive Grid Playground

Experiment with grid properties and see the results in real-time. Adjust columns, gaps, flow, and item spanning.

Grid Container

Item Properties

Generated CSS
.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

Flexbox vs Grid

Both are essential layout tools, but they excel in different scenarios. See the same content rendered by each system.

FlexboxOne-dimensional
1
2
3
4
5
Flexbox
.cards {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.card {
    flex: 1 1 200px;
    /* Items grow/shrink from 200px basis */
    /* Cannot control exact column count */
}
GridTwo-dimensional
1
2
3
4
5
Grid
.cards {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    /* Exact control: always fills the row */
    /* Consistent column widths */
}

Verdict: Both work, but Grid's auto-fit + minmax() gives consistent column widths. Flexbox items may grow unevenly on the last row.

Grid Best Practices

Use FR Units

The fr unit creates flexible tracks that share available space proportionally. Prefer fr over percentages for fluid layouts.

Mobile-First Grid

Start with a single column on mobile, then add complexity for larger screens using media queries or auto-fit.

Combine with Flexbox

Use Grid for page-level layout, Flexbox for component alignment. They work brilliantly together!

Explore More Layout Magic

You've mastered Grid! Time to explore more layout techniques and visual effects.