The grid-template property is a shorthand for defining rows, columns, and named areas of a grid in one declaration.
01
Shorthand
One rule.
02
Rows
Track sizes.
03
Columns
After slash.
04
Areas
Named zones.
05
none
Default.
06
Container
Grid parent.
Fundamentals
Introduction
The grid-template property in CSS is a shorthand property that allows you to define the rows, columns, and areas of a grid layout in a single declaration. This property is essential for creating complex grid layouts with ease and flexibility, making it a powerful tool in modern web design.
Definition and Usage
Set grid-template on a grid container with display: grid. You can define row track sizes, column track sizes, and named grid areas together. The slash (/) separates row definitions from column definitions.
💡
Beginner Tip
Read grid-template from top to bottom for rows, then after the slash for columns. Named area strings go on the row side before each row’s size.
Foundation
📝 Syntax
The grid-template property can set grid-template-rows, grid-template-columns, and named grid areas simultaneously:
The default value of the grid-template property is none, meaning that no explicit grid layout is defined and the browser will use its default behavior.
Syntax Rules
Applies to grid containers only, not individual grid items.
The slash separates row track definitions from column track definitions.
Named area strings must form a valid rectangular grid.
Resets implicit grid properties when set to a value other than none.
auto rows grow with content. Two equal 1fr columns create a responsive two-column flow.
A11y
♿ Accessibility
Keep DOM order meaningful when named areas reorder visual layout.
Use semantic HTML such as <header>, <nav>, <main>, and <footer>.
Do not rely on grid position alone to convey structure; use headings and landmarks.
Test keyboard tab order when sidebar and content are visually reordered.
Verify layouts at small widths where templates may need media query overrides.
🧠 How grid-template Works
1
Container becomes a grid
display: grid enables grid formatting on the container.
Grid
2
grid-template is set
Rows, columns, and optional named areas are defined in one value.
Template
3
Browser creates tracks
Row and column tracks are sized. Named areas map to regions.
Tracks
=
▦
Structured layout
Items fill the defined tracks or snap to named areas via grid-area.
Compatibility
🖥 Browser Compatibility
The grid-template property is well-supported in modern browsers, including recent versions of Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Modern browsers
grid-template everywhere
Grid template shorthand works in all major modern grid implementations.
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-template property97% supported
Bottom line: Safe for modern projects. Test named area layouts across target browsers.
Wrap Up
🎉 Conclusion
The grid-template property simplifies the process of defining complex grid layouts by combining multiple grid-related properties into a single declaration. By using this property, you can create responsive and flexible grid-based designs that adapt to various screen sizes and resolutions.
Experiment with different grid configurations to fully leverage the power of CSS Grid Layout. Start with rows and columns, then add named areas for page-level layouts.