CSS
CSS Grid Cheat Sheet — Properties Reference
CSS Grid gives you two-dimensional layout. Container properties define the grid; item properties place things inside it.
Put it into practice with the matching tool.
Try the Grid playground →Advertisement
Defining the grid
display: gridMake the element a grid containergrid-template-columns: 1fr 1fr 1frThree equal columnsgrid-template-columns: repeat(3, 1fr)Same, written with repeat()grid-template-rows: 100px autoFixed first row, content-sized secondgap: 16pxSpace between rows and columnsgrid-auto-flow: columnPlace new items in columns instead of rowsTrack sizing
1frOne fraction of the free spaceminmax(200px, 1fr)At least 200px, grows to fillautoSize to the contentrepeat(auto-fit, minmax(200px, 1fr))Responsive columns with no media queriesmin-content / max-contentSmallest / largest the content can bePlacing items
grid-column: 1 / 3Span from line 1 to line 3grid-column: span 2Span two columns from wherever it landsgrid-row: 2 / 4Span rows 2 to 4grid-area: headerPlace into a named template areagrid-template-areas: "hd hd" "sb mn"Name regions of the layoutAlignment
justify-items: centerAlign all items horizontally in their cellalign-items: centerAlign all items vertically in their cellplace-items: centerShorthand for both — centers everythingjustify-content: space-betweenDistribute the whole grid horizontallyjustify-self / align-selfOverride alignment for a single itemCommon recipes
display:grid; place-items:center; min-height:100vhCenter one thing on the whole screengrid-template-columns: repeat(auto-fill, minmax(240px,1fr))Responsive card gridgrid-template-columns: 250px 1frSidebar + main contentgrid-column: 1 / -1Make an item span every column