Learn how to create complex two-dimensional layouts using CSS Grid
Grid Container and Items
display
property to grid
or inline-grid
:
grid-template-columns
and grid-template-rows
properties define the columns and rows of the grid with a space-separated list of values.
Grid Template Columns and Rows
fr
unit represents a fraction of the available space in the grid container.
repeat()
function is a shorthand for repeating patterns.
minmax()
function defines a size range, setting minimum and maximum sizes.
auto-fill
and auto-fit
keywords create as many tracks as will fit in the container.
auto-fill vs auto-fit
grid-template-areas
property defines named grid areas, providing a visual representation of the layout.
Grid Template Areas
grid-gap
property (or its longhand properties row-gap
and column-gap
) sets the spacing between grid cells.
grid-gap
, grid-row-gap
, and grid-column-gap
are deprecated in favor of gap
, row-gap
, and column-gap
, which work in both Grid and Flexbox.Grid Lines
grid-column
and grid-row
properties determine a grid item’s location and span within the grid.
span
keyword.
Grid Item Spanning
grid-area
property is a shorthand for grid-row-start
, grid-column-start
, grid-row-end
, and grid-column-end
.
grid-template-areas
.
justify-items
and align-items
properties align grid items within their cells.
Justify Items and Align Items
justify-content
and align-content
properties align the entire grid within the container when the grid is smaller than the container.
Justify Content and Align Content
justify-self
and align-self
properties allow individual grid items to override the container’s alignment settings.
grid-auto-rows
and grid-auto-columns
properties define the size of implicitly created grid tracks.
grid-auto-flow
property controls how the auto-placement algorithm works.
Grid Auto Flow
minmax()
, auto-fill
, and auto-fit
.
grid-template
property is a shorthand for grid-template-rows
, grid-template-columns
, and grid-template-areas
.
grid
property is a shorthand for all grid properties.
display: grid
grid-template-columns
and grid-template-rows
grid-column
and grid-row
minmax()
, auto-fill
, and auto-fit
grid-template-areas
for more readable layouts