{}const=>[]async()letfn</>var
WebBasics

What is Grid CSS?

You will learn what CSS Grid is, why it is needed and how to work with it. Simple examples and tips for getting started with the grid.

К

Kodik

Author

2 min read

Introduction: What is Grid CSS? ⚡

If you're just starting out in web development, you may have heard of CSS Grid. But what is it, why is it needed, and how does it help to create websites? Let's find out!

CSS Grid is a tool for marking up a grid on a page. With Grid, you can create a variety of layouts with complex element arrangements without complicated tricks and hacks. 🤓

Why do you need Grid?

Grid allows you to easily create complex layouts and manage the placement of elements on the site. It simplifies the markup and gives you more options for defining the look of your site. With Grid, you can divide your page into sections and simply attach elements to them.

Simple example of Grid layout

Let's look at a very simple example of a Grid layout. To begin with, we need an HTML container and several elements:

<div class="grid-container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>

Now a little CSS to transform our grid:

.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.item {
  background-color: #f0f0f0;
  padding: 20px;
  text-align: center;
}

We created a grid that consists of two columns (grid-template-columns: 1fr 1fr; is responsible for this). With the help of gap: 20px;, we added space between the elements.

Main concepts in Grid CSS

  • Grid Container (container grid) is an element that contains all your grid elements.

  • Grid Items (grid elements) are external elements in the container.

  • Grid Lines (grid lines) — vertical and horizontal lines that divide the grid into cells.

What skills do you need to work with Grid CSS? 🚀

To get started with CSS Grid, you need to know the basics of HTML and CSS. In addition, a little knowledge of layout and basic practice with Flexbox will help you better understand Grid.

Examples for practice

To understand Grid CSS, try creating a simple grid with a different number of columns. Change the values of grid-template-columns to better understand how this tool works.

.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

Here we use repeat(3, 1fr) to create a grid of three equal columns.

Conclusion 🎉

Now you know the basics of CSS Grid and can start trying to create your first grids. If you are interested in this topic, write to us, and we will create a mini-course on working with Docker in the simplest and most understandable language!

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card