π What is grid-template?
grid-template is a shorthand property in CSS Grid that lets you definerows, columns, and grid areas β all in one place. It combines these three properties:
- grid-template-rows
- grid-template-columns
- grid-template-areas
This makes it easier to create visually structured layouts with very compact, readable syntax.
π Basic Syntax
Grid Template Syntax
grid-template:
<'grid-template-rows'> /
<'grid-template-columns'>;You can also include grid-template-areas before the slash.
π§± Example 1: Just Rows & Columns
Rows + Columns
.container {
display: grid;
grid-template: 100px 1fr 80px / 200px 1fr 200px;
}This creates:
- 3 rows β 100px, 1fr, 80px
- 3 columns β 200px, 1fr, 200px
πΊοΈ Example 2: Rows + Columns + Areas
Complete Template
.container {
display: grid;
grid-template:
"header header header" 80px
"sidebar content ads" 1fr
"footer footer footer" 60px
/ 200px 1fr 200px;
}Breakdown:
| Row | Area Names | Height |
|---|---|---|
| 1 | "header header header" | 80px |
| 2 | "sidebar content ads" | 1fr |
| 3 | "footer footer footer" | 60px |
π Visual Structure

π§ Why Use grid-template?
- Makes large layout definitions easier to read
- Lets you define the entire grid in one block
- Visually matches the design/wireframe
- Reduces CSS complexity and improves maintainability
π Equivalent Longhand Example
Without Shorthand
grid-template-rows: 80px 1fr 60px;
grid-template-columns: 200px 1fr 200px;
grid-template-areas:
"header header header"
"sidebar content ads"
"footer footer footer";Using grid-template combines all of this into a single property, making it cleaner and easier.
π§© grid-template with repeat() and minmax()
Advanced Grid Template
grid-template:
"title title" auto
"nav content" 1fr
/ 250px minmax(300px, 1fr);This creates a responsive layout with flexible content width.
β οΈ Important Notes
Note
Note
π§© Practical Layout Example
Dashboard Layout
.dashboard {
display: grid;
grid-template:
"topbar topbar" 70px
"menu main" 1fr
"menu footer" 60px
/ 250px 1fr;
}β’ Left side = vertical menu β’ Top = full-width header β’ Right = main content & footer
π₯ Summary
grid-template is a powerful shorthand that allows you to define rows, columns, and areas in a single, beautifully organized block of CSS. It improves readability, reduces code, and makes complex layouts much easier to visualize.
Learn more fromMDN Docs π