🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Grid Display

The most powerful layout system in CSS available. Create complex layouts easily.

style.css
.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
1
2
3
4
grid.html
1 / 8
🏗️

Tutor:CSS Grid Layout is a two-dimensional system. To start, we define a container with display: grid. This enables grid properties for direct children.


Grid Mastery Tree

Unlock nodes by learning layout tracks and areas.

Concept 1: The Grid Container

To start using Grid, you need to define a container element as a grid with display: grid, display: inline-grid, or display: subgrid.

System Check

Which property activates the grid context?


Community Holo-Net

Share Grid Layouts

Created a complex dashboard or gallery? Share your grid-template structures.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Grid Layout

Author

Pascual Vila

Frontend Instructor.

CSS Grid Layout excels at dividing a page into major regions or defining the relationship in terms of size, position, and layer, between parts of a control built from HTML primitives.

The Grid Container

We create a grid container by declaring display: grid or display: inline-grid on an element. As soon as we do this, all direct children of that element become grid items.

Grid Tracks

We define rows and columns on our grid with the grid-template-columns and grid-template-rows properties. These define grid tracks. A grid track is the space between any two lines on the grid.

The fr unit is specific to grid and represents a fraction of the available space in the grid container.

Positioning Items

You can position items by line numbers using grid-column-start, grid-column-end, grid-row-start, and grid-row-end. We can use the shorthand grid-column and grid-row to set start and end lines simultaneously.

Best Practices

Use Grid for layout and Flexbox for alignment. Grid is generally better for two-dimensional layouts (rows and columns), while Flexbox is better for one-dimensional layouts (a row or a column).

Grid Glossary

Grid Container
The element on which display: grid is applied. It's the direct parent of all grid items.
Grid Line
The dividing lines that make up the structure of the grid. They can be vertical ("column grid lines") or horizontal ("row grid lines").
Grid Track
The space between two adjacent grid lines. You can think of them as the columns or rows of the grid.
fr Unit
A flexible unit representing a fraction of the available space in the grid container.