display: gridThis element will use the grid layout method to position all its children.
display: inline-gridblock : inline-block :: grid : inline-grid
grid-template-columnsgrid-template-rowsgrid-template-areasgrid-templategrid-auto-columnsgrid-auto-rowsgridgapjustify-contentjustify-itemsalign-contentalign-itemsgrid-template-columnsSet the proportions for tracks along the inline axis of the grid container
Value: a series of valid length values
1fr 50em 35em 1fr30% 150px 30%grid-template-rowsSet the proportions for tracks along the block axis of the grid container
Value: a series of valid length values
300px 200px auto30% 150px 30%grid-template-areasAssign names to grid areas
.grid {
grid-template-columns: 40em 20em;
grid-template-rows: repeat(3, auto);
grid-template-areas:
"header header"
"body sidebar"
"footer footer";
}
grid-templateAssign rows, columns, and areas
.grid {
grid-template:
"header header" auto
"body sidebar" auto
"footer footer" auto /
40em 20em;
}
grid-template.grid {
grid-template:
"👱♀️ 👱♀️" auto
"📄 📶" auto
"🦶 🦶" auto /
40em 20em;
}
grid-auto-columnsSet size to be repeated for all tracks along the inline axis of the grid container
Value: a valid length value
200px1fr20%autogrid-auto-rowsSet size to be repeated for all tracks along the block axis of the grid container
Value: a valid length value
200px10remautogridShorthand for any pair of rows / columns values
(-template- or -auto-)
Syntax: rows / columns
gapCreates gaps between columns and rows
Formerly called grid-gap
Shorthand for row-gap column-gap
justify-contentDistributes tracks (columns) along the inline axis of the grid container
stretchstartendcenterspace-betweenspace-aroundspace-evenlyjustify-itemsDistributes children along the inline axis within their track (column)
stretchstartendcenteralign-contentDistributes tracks (rows) along the block axis of the grid container
stretchstartendcenterspace-betweenspace-aroundspace-evenlyalign-itemsAligns children on the block axis within their track (row)
startendcenterstretchbaselinefirst baselinelast baselineAny normal CSS length is a valid grid track value.
px%ptpcincmmmemremchvwvhvminvmaxfrOne “fraction” of the grid’s free space
Based on total number of fr in the row or column
Calculated after non-fr space is used
fr300px 1fr
1fr 50em 25em 1fr
.6fr 1.6fr 1fr
min-contentmax-contentThe smallest and largest space that the elements in that track can take up
min-content and max-content on CodePenminmax()Finds a value between two lengths
minmax(<min>, <max>)
minmax(10px, 1fr)
fit-content()Equivalent to minmax(auto, max-content)
Clamp argument overrides max-content
fit-content(<clamp>)
repeat()Repeats a certain value a specified number of times
repeat(<count>, <length>)
repeat(12, 1fr)
auto-fillA <count> value for repeat()
Repeats a certain value until the current track is filled
repeat(
auto-fill,
minmax(200px, 1fr)
)
auto-fitA <count> value for repeat()
Repeats a certain value until the children are accounted for
repeat(
auto-fit,
minmax(200px, 1fr)
)
auto-fill vs auto-fit on CodePen
grid-columngrid-rowgrid-areaorderalign-selfjustify-selfgrid-columnWhich column grid-line(s) this element should start (& stop) at
Numbers correspond to edges, not columns
Values: integer [/ integer]
grid-rowWhich row grid-line(s) this element should start (& stop) at
Numbers correspond to edges, not rows
Values: integer [/ integer]
grid-areaA named grid-template-areas location
Shorthand for row-start / column-start / row-end / column-end
orderChange the element’s location along the main axis
Relative to order of all siblings
Value: integer
align-selfAllows the element to override its parent’s align-items value
Value: any align-items value
justify-selfAllows the element to override its parent’s justify-items value
Value: any justify-items value
.grid {
display: grid;
justify-items: center;
align-items: center;
}
.parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
.parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: 1fr;
}
Flexbox is 1-dimensional: it sets a main axis and provides controls for positioning elements along that axis.
Grid is 2-dimensional: it sets both block and inline axes and provides controls for positioning elements along either/both axes.
jdsteinbach