- Home
- /
- CSS Grid
CSS Tutorial
Introduction
CSS Properties
CSS Designing
CSS Advance Topics
CSS FAQs
- Home
- /
- CSS Grid
CSS Grid
CSS Grid is a powerful layout system that allows you to design web pages using a two-dimensional grid of rows and columns. Unlike Flexbox (which works in one direction at a time), Grid lets you control both horizontal and vertical placement simultaneously.
With Grid, you can build complex layouts like headers, footers, sidebars, and content sections with ease.
Starting a Grid
To begin using Grid, apply display: grid
to a container. All direct children inside the container become grid items.
.grid-container {
display: grid;
}
You can also use display: inline-grid
if you want the grid container to behave like an inline element.
Defining Columns and Rows
Use grid-template-columns
and grid-template-rows
to set the structure of the grid.
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr; /* 3 equal columns */
grid-template-rows: 100px 100px; /* 2 rows of fixed height */
}
1fr
means one fraction of the available space.You can mix values like
px
,fr
,%
, orauto
.
Simple Grid Layout
CSS Grid - Learn With Arshyan
Basic Grid Example – Learn With Arshyan
1
2
3
4
5
6

Controlling Grid Item Position
You can tell specific items where to appear using grid-column
and grid-row
.
Spans 2 Columns
Spans 2 Rows
This means:
grid-column: 1 / 3
→ Start at column 1 and span to column 3 (spans 2 columns)grid-row: 2 / 4
→ Start at row 2 and span to row 4 (spans 2 rows)
Practical Layout: Header, Sidebar, Content
Let’s build a quick structure that uses CSS Grid to layout a typical webpage section.
Website Layout – Learn With Arshyan
Page Layout with CSS Grid
Header
Sidebar
Main Content
Footer

This approach makes it easy to define clear, maintainable layout sections.
Summary Table
Property | Description |
---|---|
display: grid | Turns element into a grid container |
grid-template-columns | Defines number and width of columns |
grid-template-rows | Defines height of rows |
gap | Adds space between grid items |
grid-column | Sets item’s horizontal span and position |
grid-row | Sets item’s vertical span and position |
grid-template-areas | Names layout areas for cleaner structure |
Learn With Arshyan Tip:
CSS Grid is ideal when you need a structured layout that involves both rows and columns. It works especially well for entire pages, dashboard layouts, and split-screen designs.