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.
Fundamentals
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.
Foundation
📝 Syntax
The grid property is a shorthand for defining grid-related properties in one declaration. The basic syntax is as follows:
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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Type
Shorthand property
Applies to
Grid containers
Inherited
No
Requires
display: grid
Common column pattern
repeat(3, 1fr)
Reference
💎 Property Values
The grid shorthand can set these sub-properties:
Sub-property
Description
grid-template-rows
Specifies the sizes of the rows
grid-template-columns
Specifies the sizes of the columns
grid-template-areas
Defines named grid areas
grid-auto-flow
Controls how auto-placed items are inserted in the grid
grid-auto-rows
Specifies the size of auto-generated rows
grid-auto-columns
Specifies the size of auto-generated columns
Preview
👀 Live Preview
A simple 2-row × 3-column grid with equal-width columns:
1
2
3
4
5
6
Hands-On
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.
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.
auto-fill creates as many columns as will fit at the minimum size. Columns grow with 1fr when extra space is available.
A11y
♿ 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.
Compatibility
🖥 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 Chrome57+ · Desktop & Mobile
Full support
Mozilla Firefox52+ · Desktop & Mobile
Full support
Apple Safari10.1+ · macOS & iOS
Full support
Microsoft Edge16+ · 79+ Chromium
Full support
Opera44+
Full support
grid property97% supported
Bottom line: CSS Grid is safe for modern projects. Use feature queries only if you must support very old browsers.
Wrap Up
🎉 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.
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.