Create powerful multi-device layouts quickly and easily with the default 12-column, nest-able Foundation grid. If you're familiar with grid systems, you'll feel right at home. If not, you'll learn quickly.
Start by adding an element with a class of .row
. This will create a horizontal block to contain vertical columns. Then add <div>
s with a .column
class within that row. You can use .column
or .columns
- the only difference is grammar. Specify the widths of each column with the .small-n
, .medium-n
, and large-n
classes, where n represents a number of columns.
Foundation is mobile-first. Code for small screens first, and larger devices will inherit those styles. Customize for larger screens as necessary.
<div class="grid-example">
<div class="row">
<div class="small-2 large-4 columns"></div>
<div class="small-4 large-4 columns"></div>
<div class="small-6 large-4 columns"></div>
</div>
<div class="row">
<div class="large-3 columns"></div>
<div class="large-6 columns"></div>
<div class="large-3 columns"></div>
</div>
<div class="row">
<div class="small-6 large-2 columns"></div>
<div class="small-6 large-8 columns"></div>
<div class="small-12 large-2 columns"></div>
</div>
<div class="row">
<div class="small-3 columns"></div>
<div class="small-9 columns"></div>
</div>
<div class="row">
<div class="large-4 columns"></div>
<div class="large-8 columns"></div>
</div>
<div class="row">
<div class="small-6 large-5 columns"></div>
<div class="small-6 large-7 columns"></div>
</div>
<div class="row">
<div class="large-6 columns"></div>
<div class="large-6 columns"></div>
</div>
</div>
Note that, by default, a .row
element will occupy the entire width of its parent. In the event that your grid-layout has no parent, you may use the .grid-container
class to constrain the width of your grid.
<div class="grid-container grid-example">
<div class="row">
<div class="small-2 large-4 columns"></div>
<div class="small-4 large-4 columns"></div>
<div class="small-6 large-4 columns"></div>
</div>
</div>
The construction of our grid is such that the exterior columns will not have any gutters on their outward facing sides. This is to say that the left- and right-most columns will not have any additional spacing between them and their containers.
<div class="bg-off-white">
<div class="row grid-spacing-example ">
<div class="small-4 columns"></div>
<div class="small-4 columns"></div>
<div class="small-4 columns"></div>
</div>
</div>
As such, it is the responsibility of a grid's container class to supply appropriate spacing between the grid elements and their neighbors in the UI. It is recommended that this be implemented using the various padding utility-classes available.
For example, below, we use the .padding-medium
class to apply spacing around our grid.
<div class="bg-off-white padding-medium">
<div class="row grid-spacing-example">
<div class="small-4 columns"></div>
<div class="small-4 columns"></div>
<div class="small-4 columns"></div>
</div>
</div>
In other contexts, we could use a variety of other padding-classes for a similar effect, but with different measurements.
Another quality of the construction of our grid is that the column itself is actually intended to act as a wrapper around sub-elements rather than being the element itself. This can be seen quite clearly when demonstrating columns with a background-color.
<div class="bg-off-white padding-medium">
<div class="row grid-fill-example">
<div class="small-4 columns cell-props"></div>
<div class="small-4 columns cell-props"></div>
<div class="small-4 columns cell-props"></div>
</div>
</div>
In the example above, the .cell-props
class applies a background-color and a border. Because it is being applied directly to the column itself rather than to a child, the grid does not appear to be correctly spaced.
In the example below, we fix this by applying the .cell-props
class to a child of a column element.
<div class="bg-off-white padding-medium">
<div class="row grid-fill-example">
<div class="small-4 columns">
<div class="cell-props"></div>
</div>
<div class="small-4 columns">
<div class="cell-props"></div>
</div>
<div class="small-4 columns">
<div class="cell-props"></div>
</div>
</div>
</div>
Note that throughout this page, we apply special CSS to better visually illustrate our examples. In these examples, sub-elements such as the ones described above do not exist.
Small grids expand to large screens easier than large grids cram into small screens.
<div class="grid-example">
<div class="row">
<div class="small-2 columns"></div>
<div class="small-10 columns"></div>
</div>
<div class="row">
<div class="small-3 columns"></div>
<div class="small-9 columns"></div>
</div>
</div>
Medium sized screens will inherit styles from small, unless you specify a different layout, using the medium grid classes.
<div class="grid-example">
<div class="row">
<div class="small-4 medium-2 columns"></div>
<div class="small-8 medium-10 columns"></div>
</div>
<div class="row">
<div class="medium-3 columns"></div>
<div class="medium-9 columns"></div>
</div>
</div>
You can nest the grids indefinitely, though at a certain point it will get absurd.
<div class="grid-example">
<div class="row">
<div class="small-8 columns">
<div class="row">
<div class="small-8 columns">
<div class="row">
<div class="small-8 columns"></div>
<div class="small-4 columns"></div>
</div>
</div>
<div class="small-4 columns"></div>
</div>
</div>
<div class="small-4 columns"></div>
</div>
</div>
Move blocks up to 11 columns to the right by using classes like .large-offset-1
and .small-offset-3
.
<div class="grid-example">
<div class="row">
<div class="large-1 columns"></div>
<div class="large-11 columns"></div>
</div>
<div class="row">
<div class="large-1 columns"></div>
<div class="large-10 large-offset-1 columns"></div>
</div>
<div class="row">
<div class="large-1 columns"></div>
<div class="large-9 large-offset-2 columns"></div>
</div>
<div class="row">
<div class="large-1 columns"></div>
<div class="large-8 large-offset-3 columns"></div>
</div>
</div>
In order to work around browsers' different rounding behaviors, Foundation will float the last column in a row to the right so the edge aligns. If your row doesn't have a count that adds up to 12 columns, you can tag the last column with a class of .end
in order to override that behavior.
<div class="grid-example">
<div class="row">
<div class="medium-3 columns"></div>
<div class="medium-3 columns"></div>
<div class="medium-3 columns"></div>
</div>
<div class="row">
<div class="medium-3 columns"></div>
<div class="medium-3 columns"></div>
<div class="medium-3 columns end"></div>
</div>
</div>
The .collapse
class lets you remove column gutters (padding).
<div class="grid-example">
<div class="row collapse">
<div class="small-6 columns"></div>
<div class="small-6 columns"></div>
</div>
</div>
There are times when you won't want each media query to be collapsed or uncollapsed. In this case, use the media query size you want and collapse or uncollapse and add that to your .row
element. Example removes the gutter at the large breakpoint and then adds the gutter to columns at medium and small.
<div class="grid-example">
<div class="row medium-uncollapse large-collapse">
<div class="small-6 columns"></div>
<div class="small-6 columns"></div>
</div>
</div>
Center your columns by adding a class of .small-centered
to your column. Large will inherit small centering by default, but you can also center solely on large by applying a .large-centered
class. To uncenter on large screens use .large-uncentered
.
<div class="grid-example">
<div class="row">
<div class="small-3 small-centered columns"></div>
</div>
<div class="row">
<div class="small-6 large-centered columns"></div>
</div>
<div class="row">
<div class="small-9 small-centered large-uncentered columns"></div>
</div>
<div class="row">
<div class="small-11 small-centered columns"></div>
</div>
</div>
Using these source ordering classes, you can shift columns around between breakpoints. This means if you place sub-navigation below main content on small displays, you have the option to position the sub-navigation on either the left or right of the page for large displays. Prefix push/pull with the size of the device you want to apply the styles to. .medium-push-n
, large-push-n
(where n
represents a number of columns) is the syntax you'll use. Use large-reset-order
to reset pushed or pulled columns to their original position on large screens.
<div class="grid-example">
<div class="row">
<div class="small-10 small-push-2 columns"></div>
<div class="small-2 small-pull-10 columns"></div>
</div>
<div class="row">
<div class="large-9 large-push-3 columns"></div>
<div class="large-3 large-pull-9 columns"></div>
</div>
<div class="row">
<div class="large-8 large-push-4 columns"></div>
<div class="large-4 large-pull-8 columns"></div>
</div>
<div class="row">
<div class="small-5 small-push-7 medium-7 medium-push-5 columns"></div>
<div class="small-7 small-pull-5 medium-5 medium-pull-7 columns"></div>
</div>
<div class="row">
<div class="medium-6 medium-push-6 columns"></div>
<div class="medium-6 medium-pull-6 columns"></div>
</div>
</div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat nonproident, sunt in culpa qui officia deserunt mollit anim id est laborum.