Grid

Atomic CSS grid classes allow you to quickly add native css grids to your container.

Overview

CSS Grids are the most powerful layout system available in CSS. It has two dimensions, meaning it can handle both columns and rows simultaneously, unlike flex layouts which can only do one at a time. Applying .d-grid to a container will lay out its children according to the CSS Grid layout spec. Adding atomic modifying classes will change the layout’s behavior. Applying classes to an individual .grid--item will change that cell’s behavior.

Examples

<div class="d-grid">
    <div class="grid--item"></div>
</div>
.grid--item
.grid--col-all
.grid--item
.grid--col1
.grid--row2
.grid--item
.grid--col3
.grid__2
.grid--item
.grid--item
.grid--item
.grid--item
.grid--item
.grid--col2
.grid--item
.grid--col1
.grid--item
.grid--col-all

Columns

To define a discrete number of columns in your grid layout, you can add a grid__[x] modifying class.

Column classes

ClassOutputDefinitionResponsive?
.grid__1grid-template-columns: repeat(1, minmax(0, 1fr))Creates a grid layout with 1 columnYes
.grid__2grid-template-columns: repeat(2, minmax(0, 2fr))Creates a grid layout with 2 columnsYes
.grid__3grid-template-columns: repeat(3, minmax(0, 3fr))Creates a grid layout with 3 columnsYes
.grid__4grid-template-columns: repeat(4, minmax(0, 4fr))Creates a grid layout with 4 columnsYes
.grid__5grid-template-columns: repeat(5, minmax(0, 5fr))Creates a grid layout with 5 columnsYes
.grid__6grid-template-columns: repeat(6, minmax(0, 6fr))Creates a grid layout with 6 columnsYes
.grid__7grid-template-columns: repeat(7, minmax(0, 7fr))Creates a grid layout with 7 columnsYes
.grid__8grid-template-columns: repeat(8, minmax(0, 8fr))Creates a grid layout with 8 columnsYes
.grid__9grid-template-columns: repeat(9, minmax(0, 9fr))Creates a grid layout with 9 columnsYes
.grid__10grid-template-columns: repeat(10, minmax(0, 10fr))Creates a grid layout with 10 columnsYes
.grid__11grid-template-columns: repeat(11, minmax(0, 11fr))Creates a grid layout with 11 columnsYes
.grid__12grid-template-columns: repeat(1, minmax(0, 12fr))Creates a grid layout with 12 columnsYes
.grid__autogrid-template-columns: auto 1frCreates a grid layout with auto-sized columns based on their contentYes

Columns examples

<div class="d-grid grid__1"></div>
<div class="d-grid grid__2"></div>
<div class="d-grid grid__3"></div>
<div class="d-grid grid__4"></div>
<div class="d-grid grid__5"></div>
<div class="d-grid grid__6"></div>
<div class="d-grid grid__7"></div>
<div class="d-grid grid__8"></div>
<div class="d-grid grid__9"></div>
<div class="d-grid grid__10"></div>
<div class="d-grid grid__11"></div>
<div class="d-grid grid__12"></div>
<div class="d-grid grid__auto"></div>
1
1
2
1
2
3
1
2
3
4
1
2
3
4
5
1
2
3
4
5
6
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4

Column and row spans

You can apply grid--col[x] to your columns, and grid--row[x] to your rows to span a specific number of columns or rows.

Column spanning classes

ClassOutputDefinitionResponsive?
.grid--col-allgrid-column: 1 / -1Span all the columnsYes
.grid--col1grid-column: span 1Span 1 columnYes
.grid--col2grid-column: span 2Span 2 columnsYes
.grid--col3grid-column: span 3Span 3 columnsYes
.grid--col4grid-column: span 4Span 4 columnsYes
.grid--col5grid-column: span 5Span 5 columnsYes
.grid--col6grid-column: span 6Span 6 columnsYes
.grid--col7grid-column: span 7Span 7 columnsYes
.grid--col8grid-column: span 8Span 8 columnsYes
.grid--col9grid-column: span 9Span 9 columnsYes
.grid--col10grid-column: span 10Span 10 columnsYes
.grid--col11grid-column: span 11Span 11 columnsYes
.grid--col12grid-column: span 12Span 12 columnsYes

Column examples

<div class="d-grid grid__12">
    <div class="grid--col-all"></div>
    <div class="grid--col1"></div>
    <div class="grid--col2"></div>
    <div class="grid--col3"></div>
    <div class="grid--col4"></div>
    <div class="grid--col5"></div>
    <div class="grid--col6"></div>
    <div class="grid--col7"></div>
    <div class="grid--col8"></div>
    <div class="grid--col9"></div>
    <div class="grid--col10"></div>
    <div class="grid--col11"></div>
    <div class="grid--col12"></div>
</div>
.grid--col-all
.grid--col1
.grid--col2
.grid--col3
.grid--col4
.grid--col5
.grid--col6
.grid--col7
.grid--col8
.grid--col9
.grid--col10
.grid--col11
.grid--col12

Row classes

ClassOutputDefinitionResponsive?
.grid--row-allgrid-row: 1 / -1Span all the rowsYes
.grid--row1grid-row: span 1Span 1 rowYes
.grid--row2grid-row: span 2Span 2 rowsYes
.grid--row3grid-row: span 3Span 3 rowsYes
.grid--row4grid-row: span 4Span 4 rowsYes
.grid--row5grid-row: span 5Span 5 rowsYes
.grid--row6grid-row: span 6Span 6 rowsYes
.grid--row7grid-row: span 7Span 7 rowsYes
.grid--row8grid-row: span 8Span 8 rowsYes
.grid--row9grid-row: span 9Span 9 rowsYes
.grid--row10grid-row: span 10Span 10 rowsYes
.grid--row11grid-row: span 11Span 11 rowsYes
.grid--row12grid-row: span 12Span 12 rowsYes

Row example

<div class="d-grid grid__4">
    <div class="grid--col2 grid--row4"></div>
    <div class="grid--col2"></div>
    <div class="grid--col2"></div>
    <div class="grid--col2"></div>
    <div class="grid--col2"></div>
</div>
.grid--col2
.grid--row4
.grid--col2
.grid--col2
.grid--col2
.grid--col2

Autoflow

If you have grid items that you don’t explicitly place on the grid, the auto-placement algorithm kicks in to automatically place the items.

Autoflow classes

ClassOutputDefinitionResponsive?
.g-af-rowgrid-auto-flow: rowItems are placed by filling each row in turn, adding new rows as necessary. The default.Yes
.g-af-columngrid-auto-flow: columnItems are placed by filling each column in turn, adding new columns as necessary.Yes
.g-af-densegrid-auto-flow: denseDense packing algorithm attempts to fill in holes earlier in the grid, if smaller items come up later. This may cause items to appear out-of-order, when doing so would fill in holes left by larger items.Yes

Autoflow examples

<div class="d-grid g-af-row"></div>
<div class="d-grid g-af-column"></div>
<div class="d-grid g-af-dense"></div>
.g-af-row
1
2
3
.g-af-column
1
2
3
4
5
6
7
8
9
10
11
12
.g-af-dense
1
2
3
4
5
6
7
8
9
10
11
12

Start and end

If you’d like to offset a column or row and specify its start and end positioning classes, you can apply these atomic classes.

Column start and end classes

ClassOutputDefinitionResponsive?
.grid--col-start1grid-column-start: 1Start at the 1st columnYes
.grid--col-start2grid-column-start: 2Start at the 2nd columnYes
.grid--col-start3grid-column-start: 3Start at the 3rd columnYes
.grid--col-start4grid-column-start: 4Start at the 4th columnYes
.grid--col-start5grid-column-start: 5Start at the 5th columnYes
.grid--col-start6grid-column-start: 6Start at the 6th columnYes
.grid--col-start7grid-column-start: 7Start at the 7th columnYes
.grid--col-start8grid-column-start: 8Start at the 8th columnYes
.grid--col-start9grid-column-start: 9Start at the 9th columnYes
.grid--col-start10grid-column-start: 10Start at the 10th columnYes
.grid--col-start11grid-column-start: 11Start at the 11th columnYes
.grid--col-start12grid-column-start: 12Start at the 12th columnYes
.grid--col-end2grid-column-end: 2End at the start of 2nd columnYes
.grid--col-end3grid-column-end: 3End at the start of 3rd columnYes
.grid--col-end4grid-column-end: 4End at the start of 4th columnYes
.grid--col-end5grid-column-end: 5End at the start of 5th columnYes
.grid--col-end6grid-column-end: 6End at the start of 6th columnYes
.grid--col-end7grid-column-end: 7End at the start of 7th columnYes
.grid--col-end8grid-column-end: 8End at the start of 8th columnYes
.grid--col-end9grid-column-end: 9End at the start of 9th columnYes
.grid--col-end10grid-column-end: 10End at the start of 10th columnYes
.grid--col-end11grid-column-end: 11End at the start of 11th columnYes
.grid--col-end12grid-column-end: 12End at the start of 12th columnYes
.grid--col-end13grid-column-end: 13End at the start of 13th columnYes

Column start and end examples

<div class="d-grid grid__4">
    <div class="grid--col-start1 grid--col-end4"></div>
    <div class="grid--col-start2 grid--col-end4"></div>
    <div class="grid--col2 grid--col-end5"></div>
</div>
.grid--col-start1 .grid--col-end4
.grid--col-start2 .grid--col-end4
.grid--col2 .grid--col-end5

Row start and end classes

ClassOutputDefinitionResponsive?
.grid--row-start1grid-row-start: 1Start at the 1st rowYes
.grid--row-start2grid-row-start: 2Start at the 2nd rowYes
.grid--row-start3grid-row-start: 3Start at the 3rd rowYes
.grid--row-start4grid-row-start: 4Start at the 4th rowYes
.grid--row-start5grid-row-start: 5Start at the 5th rowYes
.grid--row-start6grid-row-start: 6Start at the 6th rowYes
.grid--row-start7grid-row-start: 7Start at the 7th rowYes
.grid--row-start8grid-row-start: 8Start at the 8th rowYes
.grid--row-start9grid-row-start: 9Start at the 9th rowYes
.grid--row-start10grid-row-start: 10Start at the 10th rowYes
.grid--row-start11grid-row-start: 11Start at the 11th rowYes
.grid--row-start12grid-row-start: 12Start at the 12th rowYes
.grid--row-end2grid-row-end: 2End at the start of 2nd rowYes
.grid--row-end3grid-row-end: 3End at the start of 3rd rowYes
.grid--row-end4grid-row-end: 4End at the start of 4th rowYes
.grid--row-end5grid-row-end: 5End at the start of 5th rowYes
.grid--row-end6grid-row-end: 6End at the start of 6th rowYes
.grid--row-end7grid-row-end: 7End at the start of 7th rowYes
.grid--row-end8grid-row-end: 8End at the start of 8th rowYes
.grid--row-end9grid-row-end: 9End at the start of 9th rowYes
.grid--row-end10grid-row-end: 10End at the start of 10th rowYes
.grid--row-end11grid-row-end: 11End at the start of 11th rowYes
.grid--row-end12grid-row-end: 12End at the start of 12th rowYes
.grid--row-end13grid-row-end: 13End at the start of 13th rowYes

Row start and end examples

<div class="d-grid grid__4">
    <div class="grid--col2 grid--row-start2 grid--row-end4"></div>
    <div class="grid--col2"></div>
    <div class="grid--col2"></div>
    <div class="grid--col2"></div>
    <div class="grid--col2"></div>
</div>
.grid--col2
.grid--row-start2
.grid--row-end4
.grid--col2
.grid--col2
.grid--col2
.grid--col2

Alignment

On the grid container, you can apply align-items to the y axis and justify-items to the x axis. On individual items, you can apply align-self on the y axis, and justify-self on the x axis.

Alignment classes

ClassOutputDefinitionResponsive?
.ji-autojustify-items: autoUse the parent's justify value.Yes
.ji-centerjustify-items: centerThe items are packed flush to each other toward the center of x axis.Yes
.ji-startjustify-items: startThe items are packed flush to each other toward the left.Yes
.ji-endjustify-items: endThe items are packed flush to each other toward the right.Yes
.ji-stretchjustify-items: stretchItems stretch to fill the available spaceYes
.ji-unsetjustify-items: unsetRemoves any justification, effectively resetting the valueYes
.js-autojustify-self: autoUse the parent's justify value.Yes
.js-centerjustify-self: centerThe item is packed flush to the others toward the center of x axis.Yes
.js-startjustify-self: startThe item is packed flush to the others toward the left.Yes
.js-endjustify-self: endThe item is packed flush to the others toward the right.Yes
.js-stretchjustify-self: stretchItem stretches to fill the available spaceYes
.js-unsetjustify-self: unsetRemoves any justification, effectively resetting the valueYes
.ai-baselinealign-items: baselineAligns items along the baseline of a parent's cross axis.Yes
.ai-centeralign-items: centerCenters child elements along the parent's cross axis.Yes
.ai-endalign-items: endPlaces child elements at the end of the parent's cross axis.Yes
.ai-startalign-items: startPlaces child elements at the start of the parent's cross axis.Yes
.ai-stretchalign-items: stretchStretches child elements along the parent's cross axis.Yes
.as-autoalign-self: auto;Auto re-aligns a child element along the parent's main axis.Yes
.as-baselinealign-self: baseline;Re-aligns a child element along the baseline of the parent's main axis.Yes
.as-centeralign-self: center;Centers a child element along the parent's main axis.Yes
.as-endalign-self: end;Re-aligns a child element to the end of the parent's main axis.Yes
.as-startalign-self: start;Re-aligns a child element to the start of the parent's main axis.Yes
.as-stretchalign-self: stretch;Stretches a child element along the parent's main axis.Yes

Alignment examples

<div class="d-grid ji-center ai-center">
    <div class="grid--item as-start"></div>
    <div class="grid--item"></div>
    <div class="grid--item js-end"></div></div>
Default
1
2
3
4
5
6
.ji-center .ai-center
1 .as-start
2
3 .as-stretch
4 .js-end
5
6