CSS grid Property

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The grid property is a shorthand for defining rows, columns, and areas on a CSS Grid container in one declaration.

01

Rows

Track heights.

02

Columns

Track widths.

03

Areas

Named regions.

04

fr units

Flexible size.

05

Shorthand

One property.

06

Responsive

Modern layouts.

Introduction

The CSS grid property is a powerful tool that allows web developers to create complex and responsive grid-based layouts using a straightforward and declarative syntax.

This property is part of the CSS Grid Layout Module, which enables the design of web pages using a grid system with rows and columns. With CSS Grid, you can define areas of your web page, align items, and distribute space in a way that wasn't possible with traditional CSS layout methods.

Definition and Usage

To use grid layouts, first set display: grid on a container. Then use the grid shorthand (or longhand properties like grid-template-columns) to define the track sizes. The shorthand is convenient when you want to set rows and columns together, such as grid: auto-flow / 1fr 1fr 1fr;.

💡
Beginner Tip

Start with separate properties like grid-template-rows and grid-template-columns until you understand the layout. Move to the grid shorthand once the pattern feels familiar.

📝 Syntax

The grid property is a shorthand for defining grid-related properties in one declaration. The basic syntax is as follows:

syntax.css
element {
  grid: [grid-template-rows] / [grid-template-columns];
}

However, the grid shorthand can also include other properties, such as grid-template-areas, grid-auto-flow, grid-auto-rows, and grid-auto-columns.

Basic Example

grid-basic.css
.grid-container {
  display: grid;
  grid-template-rows: 100px 100px 100px;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
grid: 100px 100px / 1fr 1fr 1fr; grid-template-columns: repeat(3, 1fr); grid-auto-rows: minmax(80px, auto);

Default Value

There is no default value for the grid property itself since it is a shorthand. The individual properties within the shorthand each have their own default values.

Syntax Rules

  • The slash (/) separates row-related values from column-related values in many shorthand forms.
  • Requires display: grid (or inline-grid) on the same element.
  • Can combine template tracks, named areas, and auto-placement rules.
  • The property is not inherited by child elements.
  • Pair with gap for spacing between grid items.

⚡ Quick Reference

QuestionAnswer
TypeShorthand property
Applies toGrid containers
InheritedNo
Requiresdisplay: grid
Common column patternrepeat(3, 1fr)

💎 Property Values

The grid shorthand can set these sub-properties:

Sub-propertyDescription
grid-template-rowsSpecifies the sizes of the rows
grid-template-columnsSpecifies the sizes of the columns
grid-template-areasDefines named grid areas
grid-auto-flowControls how auto-placed items are inserted in the grid
grid-auto-rowsSpecifies the size of auto-generated rows
grid-auto-columnsSpecifies the size of auto-generated columns

👀 Live Preview

A simple 2-row × 3-column grid with equal-width columns:

1
2
3
4
5
6

Examples Gallery

Create a simple 3×3 grid layout, then explore the grid shorthand, named areas, and responsive auto-fill columns.

🔢 Row & Column Tracks

Start with the reference example — three rows and three columns with gap spacing.

Example 1 — Simple 3×3 Grid Layout

Define fixed row heights and three equal columns with 1fr.

grid-basic.html
.grid-container {
  display: grid;
  grid-template-rows: 100px 100px 100px;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
Try It Yourself

How It Works

Each 1fr column shares available width equally. Fixed row heights create a uniform 3×3 cell structure for nine items.

Example 2 — grid Shorthand Syntax

Set rows and columns in one line using the slash separator.

grid-shorthand.css
.grid-container {
  display: grid;
  grid: 80px 80px / 1fr 1fr 1fr;
  gap: 10px;
}
Try It Yourself

How It Works

Values before the slash define rows; values after define columns. This is equivalent to setting grid-template-rows and grid-template-columns separately.

📈 Areas & Responsive Layouts

Use named areas for page sections and auto-fill for responsive card grids.

Example 3 — Page Layout with Named Areas

Define header, sidebar, main, and footer regions with grid-template-areas.

grid-areas.css
.layout {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  grid-template-columns: 200px 1fr;
  gap: 10px;
}
Try It Yourself

How It Works

Each string row in grid-template-areas maps to a grid row. Child elements use grid-area to slot into named regions.

Example 4 — Responsive Auto-Fill Grid

Create a card grid that wraps into as many columns as fit using auto-fill and minmax.

grid-responsive.css
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 1rem;
}
Try It Yourself

How It Works

auto-fill creates as many columns as will fit at the minimum size. Columns grow with 1fr when extra space is available.

♿ Accessibility

  • Keep logical source order in HTML even when grid visually reorders items with named areas.
  • Do not rely on layout alone to convey structure; use headings and landmarks (header, main, nav).
  • Test keyboard navigation when grid changes item placement on different screen sizes.
  • Ensure readable line lengths in grid cells, especially on wide screens.
  • Maintain touch target spacing with gap between interactive grid items.

🧠 How grid Works

1

Enable grid on the container

Set display: grid so the element becomes a grid formatting context.

display: grid
2

Define tracks with grid

Use the shorthand or longhand properties to set row heights, column widths, and optional named areas.

Track sizing
3

Items fill grid cells

Direct children become grid items placed into cells by source order or explicit area assignment.

Placement
=

Structured 2D layout

Rows, columns, and areas align content in a predictable, responsive grid system.

🖥 Browser Compatibility

The grid property is well-supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. For best results, always test your layout across different browsers and devices.

Baseline · Universal support

CSS Grid everywhere

Grid layout and the grid shorthand work in every major modern browser.

97% Modern browser support
Google Chrome 57+ · Desktop & Mobile
Full support
Mozilla Firefox 52+ · Desktop & Mobile
Full support
Apple Safari 10.1+ · macOS & iOS
Full support
Microsoft Edge 16+ · 79+ Chromium
Full support
Opera 44+
Full support
grid property 97% supported

Bottom line: CSS Grid is safe for modern projects. Use feature queries only if you must support very old browsers.

🎉 Conclusion

The CSS grid property is a versatile and powerful tool for creating complex, responsive web layouts with ease. By mastering this property, you can design sophisticated grid systems that adapt to various screen sizes and enhance the overall user experience.

Experiment with different grid configurations and discover the possibilities that CSS Grid offers for web design. Start with explicit rows and columns, then explore named areas and auto-fill for responsive layouts.

💡 Best Practices

✅ Do

  • Set display: grid on the container
  • Use fr units for flexible columns
  • Combine with gap for clean spacing
  • Use named areas for page layouts
  • Try auto-fill for responsive cards

❌ Don’t

  • Forget display: grid on the parent
  • Overuse fixed pixel tracks everywhere
  • Rely on visual order over DOM order
  • Mix grid and float on the same layout
  • Jump to shorthand before learning tracks

Key Takeaways

Knowledge Unlocked

Five things to remember about grid

Use these points when building grid layouts.

5
Core concepts
shorthand 02

Shorthand

Many sub-props.

Type
1fr 03

fr units

Flexible tracks.

Syntax
areas 04

Named areas

Page regions.

Layout
grid 05

display: grid

Required first.

Setup

❓ Frequently Asked Questions

The grid property is a shorthand that sets multiple grid layout values at once, such as template rows, template columns, template areas, and auto-placement rules.
There is no single default for the grid shorthand itself. Each sub-property it includes has its own initial value, such as none for grid-template rows and columns.
display: grid turns an element into a grid container. The grid property defines how rows, columns, and areas are configured on that container.
It can set grid-template-rows, grid-template-columns, grid-template-areas, grid-auto-flow, grid-auto-rows, and grid-auto-columns in one declaration.
Use grid for two-dimensional layouts with rows and columns, such as page sections and card galleries. Use flexbox for one-dimensional alignment along a single axis.

Practice in the Live Editor

Open the HTML editor, define grid rows and columns, and watch how items flow into the layout.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful