CSS grid Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The grid property is a shorthand for the explicit and implicit grid settings on a grid container. It can set grid-template-rows, grid-template-columns, grid-template-areas, grid-auto-rows, grid-auto-columns, and grid-auto-flow.

First turn the element into a grid with display: grid (or inline-grid). Then use grid to define tracks and how extra items auto-place. The property is not inherited. Unspecified sub-properties reset to their initial values. gap is not reset by this shorthand.

Standard-track.

Not deprecated and not experimental. Baseline Widely available since 2017. Internet Explorer’s old -ms-grid model is a different, incomplete system—do not treat it as modern grid.

CSS Syntax

syntax.css
grid: <grid-template> | <rows> / auto-flow … | auto-flow … / <columns> | initial | inherit;

Common pattern: rows / columns. Or fix one axis and use auto-flow on the other.

Property Values

ValueDescriptionTry it
noneNo explicit template. Tracks come from auto-placementTry it
<rows> / <columns>Sets template rows then template columnsTry it
auto-flow / <columns>Fixed columns; rows grow as items are addedTry it
<rows> / auto-flowFixed rows; columns grow as items are addedTry it
initialResets each sub-property to its initial valueTry it
inheritTakes the parent’s grid valueTry it

You can also write a full grid-template value (including areas) as the single grid value.

How to Use grid

Create a grid container, then set tracks or auto-flow with one shorthand.

  1. Set display: grid on the container.
  2. Choose a form: explicit rows / columns, or auto-flow on one axis.
  3. Add gap separately if you want gutters—the shorthand does not set them.
  4. Prefer longhands when you only change one piece of the layout.
PieceRequired?Role
display: gridYesMakes the element a grid container
grid valueYesDefines tracks, areas, and/or auto-flow
gapOptionalGutters stay independent of the shorthand

Live Preview

Six items in a grid container. Only the grid shorthand changes. Watch how tracks and flow rearrange.

You still need display: grid. The shorthand only configures the tracks and flow.

Sample
1
2
3
4
5
6

grid: 80px 80px / 1fr 1fr 1fr

CSS Examples

Each snippet focuses on the grid shorthand. Use Try It Yourself for a live editor.

Example 1 — Explicit Rows and Columns

Set two fixed rows and three flexible columns in one line.

CSS
<style>
  section {
    display: grid;
    grid: 80px 80px / 1fr 1fr 1fr;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Make a grid. display: grid creates the container.
  2. Read left of the slash. 80px 80px is two explicit rows.
  3. Read right of the slash. 1fr 1fr 1fr is three equal columns.
  4. Fill in order. Items 1–3 sit on row 1; items 4–6 sit on row 2.

Example 2 — Auto-Flow Rows

Fix three columns. Extra items create new rows automatically.

CSS
<style>
  section {
    display: grid;
    grid: auto-flow / 1fr 1fr 1fr;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Fix the columns. 1fr 1fr 1fr after the slash sets three tracks.
  2. Turn on row flow. auto-flow before the slash sets grid-auto-flow: row.
  3. Grow as needed. Six items fill two implicit rows of three.
  4. Row size. Implicit rows default to auto unless you add a size after auto-flow.

Example 3 — Auto-Flow Columns

Fix two rows. Extra items create new columns to the side.

CSS
<style>
  section {
    display: grid;
    grid: repeat(2, 60px) / auto-flow 80px;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Fix the rows. repeat(2, 60px) makes two 60px rows.
  2. Flow columns. auto-flow 80px sets column flow and makes each new column 80px wide.
  3. Fill down first. Items fill column by column: 1 then 2 in the first column, and so on.
  4. Same idea as longhands. This matches setting grid-template-rows, grid-auto-flow: column, and grid-auto-columns: 80px.

Edge Cases & Pitfalls

Most surprises come from forgetting display: grid or what the shorthand resets.

display

Needs display: grid

The grid property alone does not create a grid. Set display: grid (or inline-grid) first.

reset

Unspecified parts reset

Like other shorthands, omitted sub-properties go back to their initial values. Set only what you mean, or use a longhand for a single change.

gap

gap is not reset

Gutters stay as set. Writing a new grid value will not clear gap.

or

Explicit or implicit, not a mix in one form

A single grid declaration uses either a template form or an auto-flow form. You cannot fully define both explicit axes and custom auto sizes in every combination at once.

ie

IE -ms-grid is not modern Grid

Internet Explorer’s prefixed model lacks auto-placement, fr, and modern areas. Do not expect this shorthand to work there.

Browser Support

The grid shorthand is a browser CSS property for Grid Layout. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

grid

Supported in Chrome 57+, Firefox 52+, Safari 10.1+, and Edge 16+. Internet Explorer does not support the modern shorthand.

97% Global support
Google Chrome 57+
Full support
Mozilla Firefox 52+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 16+
Full support
Opera 44+
Full support
Samsung Internet 6.2+
Full support
Internet Explorer No modern grid
Not supported
grid Widely supported

Bottom line: Safe in current browsers. Pair with display: grid. Prefer longhands when you only need one track or flow setting.

Key Takeaways

  • Role: shorthand for template tracks, areas, and auto-flow settings.
  • Needs display: grid first. The shorthand does not create the container.
  • Forms: rows / columns, or auto-flow on one axis.
  • Gap stays. The shorthand does not reset gap.

One line: grid packs template and auto-flow settings into one declaration after you set display: grid.

Frequently Asked Questions

It is a shorthand that sets explicit grid tracks (template rows, columns, and areas) and implicit grid behavior (auto-flow, auto-rows, and auto-columns) in one declaration.
display: grid turns the element into a grid container. The grid property then defines how rows, columns, areas, and auto-placement work on that container.
No. According to the specification, gutter properties such as gap are not reset by the grid shorthand.
It turns on automatic placement along one axis. For example, grid: auto-flow / 1fr 1fr 1fr creates three columns and adds rows as needed for new items.
Use grid-template-columns, grid-template-rows, or grid-auto-flow alone when you only need to change one piece. The shorthand is handy when you set several of them together.
It is Baseline Widely available: Chrome 57+, Firefox 52+, Safari 10.1+, and Edge 16+. Internet Explorer does not support the modern shorthand. It is a browser CSS property, not a Node.js feature.

Next: grid-area

Place items with names or line shorthand.

grid-area tutorial →

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.

8 people found this page helpful