CSS grid-template Property

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

What You’ll Learn

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.

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.

📝 Syntax

The grid-template property can set grid-template-rows, grid-template-columns, and named grid areas simultaneously:

syntax.css
element {
  grid-template: none | <grid-template-rows> / <grid-template-columns> | <grid-template-areas>;
}

Basic Example with Areas

grid-template-basic.css
.grid-container {
  display: grid;
  grid-template:
    "header header" 50px
    "sidebar content" 1fr
    "footer footer" 30px / 150px 1fr;
}

Rows and Columns Only

grid-template-rows-cols.css
.grid-container {
  grid-template: 80px 1fr 40px / 1fr 1fr;
}
grid-template: none; grid-template: 1fr 1fr / 1fr 1fr; grid-template: "a b" 1fr / 1fr 1fr;

Default Value

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.
  • The property is not inherited.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toGrid containers
InheritedNo
ControlsRows, columns, and areas
Longhand partsgrid-template-rows, grid-template-columns, grid-template-areas

💎 Property Values

ValueDescription
noneNo grid layout template is defined
<grid-template-rows>Defines the row sizes of the grid
<grid-template-columns>Defines the column sizes of the grid
<grid-template-areas>Defines named grid areas within the grid

👀 Live Preview

A mini page layout with header, sidebar, content, and footer defined by grid-template:

Header
Side
Content
Footer

Examples Gallery

Build a full page layout with named areas, set rows and columns only, use repeat(), and create a simple two-column grid.

🔢 Grid Template Layouts

Start with the reference example — a header, sidebar, content, and footer layout.

Example 1 — Page Layout with Named Areas

Create a simple grid with three rows and two columns, defining specific sizes and named areas.

grid-template-areas-layout.css
.grid-container {
  display: grid;
  grid-template:
    "header header" 50px
    "sidebar content" 1fr
    "footer footer" 30px / 150px 1fr;
}

.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.footer { grid-area: footer; }
Try It Yourself

How It Works

Each quoted string defines a row of named areas. Row sizes follow each string. After the slash, column sizes define the sidebar and content widths.

Example 2 — Rows and Columns Only

Define track sizes without named areas using the slash syntax.

grid-template-rows-cols-only.css
.grid-container {
  display: grid;
  grid-template: 80px 1fr 40px / 1fr 1fr;
}
Try It Yourself

How It Works

Three row tracks (80px, flexible, 40px) and two equal columns. Items auto-place into the 3×2 grid.

📈 Template Patterns

Use repeat() and equal fractions for common grid structures.

Example 3 — repeat() in grid-template

Create a uniform grid using repeat() for rows and columns.

grid-template-repeat.css
.grid-container {
  display: grid;
  grid-template: repeat(3, 100px) / repeat(2, 1fr);
}
Try It Yourself

How It Works

repeat(3, 100px) creates three 100px rows. repeat(2, 1fr) creates two equal flexible columns.

Example 4 — Simple Two-Column Grid

Use a minimal template for a two-column card layout.

grid-template-two-col.css
.card-grid {
  display: grid;
  grid-template: auto / 1fr 1fr;
  gap: 16px;
}
Try It Yourself

How It Works

auto rows grow with content. Two equal 1fr columns create a responsive two-column flow.

♿ 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.

🖥 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 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-template property 97% supported

Bottom line: Safe for modern projects. Test named area layouts across target browsers.

🎉 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.

💡 Best Practices

✅ Do

  • Use named areas for page layouts
  • Separate rows from columns with the slash
  • Pair with grid-area on child items
  • Use fr and repeat() for flexible tracks
  • Override templates in media queries for responsive design

❌ Don’t

  • Apply on grid items instead of containers
  • Create invalid non-rectangular area shapes
  • Forget display: grid on the container
  • Rely on visual order alone for accessibility
  • Use overly complex templates when longhand is clearer

Key Takeaways

Knowledge Unlocked

Five things to remember about grid-template

Use these points when defining grid structure.

5
Core concepts
none 02

Default none

No template.

Default
/ 03

Slash

Rows / cols.

Syntax
area 04

Named areas

Page zones.

Pattern
fr 05

Flexible

1fr tracks.

Sizing

❓ Frequently Asked Questions

grid-template is a shorthand that defines grid rows, columns, and named areas in one declaration on a grid container.
The default is none, which means no explicit template is set and the browser uses default grid behavior.
grid-template-rows sets only row track sizes. grid-template can combine rows, columns, and areas together.
The slash separates row definitions from column definitions. Everything before / is rows; everything after / is columns.
grid-template-areas sets only named area strings. grid-template can include areas plus row and column sizes in one value.

Practice in the Live Editor

Open the HTML editor, change grid-template values, and build your own row and column layouts.

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