CSS Grid for Beginners

Elad Shechter
5 min readJun 20, 2018



These days, CSS Grid appears in most tech websites, yet developers are still afraid to use it.

Many of us web developers, still hold the misconception that new features in the web take ages to mature, but this isn’t the case anymore.

These days all the the major web-browsers get auto updates, chrome + firefox + edge get new updates every 1.5–4 months, including their mobile versions. Safari gets updated once a year, along with OSX/iOS.

This means that we no longer have to wait ages for new features to have support. CSS Grid isn’t an exception, it is supported in all major browsers, including Internet Explorer 11 (with some prefixes and a few syntax changes).

In this post I will teach you how to start working with CSS Grid in small, easy steps.

CSS Grid Basics

Lets take a quick look at grid terminology and start working with it.

Grid Container
As its name suggests, it is the container of the grid. When declaring display:grid, all the directly nested element children get affected (the same as in flexbox).

Grid items
Are the directly nested elements of a grid container.


display: grid;

HTML (Grid Container + Grid Items)

<div class=”grid-container”>
<header class=”main-header”></header>
<main class=”main-content”></main>
<aside class=”main-side”>
<!-- doesn’t effected!!! -->
<div class=”child-of-child”></div>
<!-- doesn’t effected!!! -->
<footer class=”main-footer”></footer>

All the nested HTML tags in the .grid-container are the grid items ( .main-header, .main-content, .main-side, .main-footer ).

Grid columns
When working with grid, we define the number of column in a row. We define it with the property grid-template-columns. Each column gets a size value, see example:


<div class="site">
<div class="main">2 - auto value</div>


display: grid;
grid-template-columns: 300px auto 300px;


Basic CSS Grid Example with CodePen

Grid Rows
We can define rows in a grid, but it is important to remember that if we don’t define any rows, we still get rows with auto height, with the amount of columns according to the grid columns we have defined. Most of the times we will prefer not to set any grid rows! (grid-template-rows)

CSS — how to set grid rows example

display: grid;
grid-template-columns: 300px auto 300px;
grid-template-rows: 50px 700px 50px; /*the height of the rows*/

Grid Cell
Every column in every row is called a grid cell.
Notice! All grid items automatically populate the grid cells according to the columns we have defined.

Grid Lines
When defining the columns and rows we get grid lines: horizontal and vertical lines that make up the grid.

With these lines we can position grid items. There are two properties that are called grid-row & grid-column, but we will focus on that in my next post, titled “CSS Grid Methods” (for intermediate level) and how to use it.

Before we continue — meet the Fraction Unit

The fr (fraction) unit is a proportional unit that was added with CSS grid, we use it to calculate ratio between cells or rows.

fr unit example:

grid-template-columns: 2fr 1fr 1fr;

Grid Gap
Grid gap is the empty space between grid rows and columns.


grid-column-gap: 10px;
grid-row-gap: 10px;
/** Or in shorthand = **/grid-gap: 10px;

Grid Areas
After declaring grid columns we can define grid-template-areas.
grid-template-areas is a way to give names to your grid areas so you can find and use them more easily. I call it my “grid map”.


CSS — Grid Areas Mapping

After we create the map, we need to reference grid items according to the map, with the property grid-area. Let’s see an example:

CSS — Reference Grid Items to Grid Areas Mapping


We are finished! we have easily created a complex CSS Grid!
Areas Method Live CodePen Example


That’s all.
I hope you’ve enjoyed this article and learned from my experience.
If you like this post, I will appreciate applause and sharing :-)

More of my CSS Grid posts:
The CSS Grid Working Methods (Intermediate Level)
Becoming a CSS Grid Ninja! (High Level!)
Supporting CSS Grid in Internet Explorer

Or my others CSS post:
CSS Architecture for Multiple Websites With SASS
Responsive Design Best Practices for Big Projects

I am Elad Shechter, Web Developer specializing in CSS & HTML design and architecture, working at Investing.com.

You Can find me in my Facebook groups:
CSS Masters
CSS Masters Israel

You can contact or follow me:
My Twitter


A lots of the examples in this post were taken from the amazing video by Morten Rand-Hendriksen, “CSS Grid Changes Everything”, really worth watching :-).