Foundation

The Grid

Create powerful multi-device layouts quickly and easily with the default 12-column, nestable Foundation grid. If you're familiar with grid systems, you'll feel right at home. If not, you'll learn quickly.

Basics

Start by adding an element with a class of .row. This will create a horizontal block to contain vertical columns. Then add elements 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-#, .medium-#, and .large-# classes.

Foundation is mobile-first. Code for small screens first, and larger devices will inherit those styles. Customize for larger screens as necessary.

<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>
24
4
64
full3
full6
full3
62
68
full2
3
9
full4
full8
65
67
full6
full6

Small Grids

Small grids expand to large screens easier than large grids cram into small screens.

<div class="row">
  <div class="small-2 columns">2 <span class="hide-for-small-only">columns</span></div>
  <div class="small-10 columns">10 columns</div>
</div>
<div class="row">
  <div class="small-3 columns">3 columns</div>
  <div class="small-9 columns">9 columns</div>
</div>
2 columns
10 columns
3 columns
9 columns

Medium Grid

Medium sized screens will inherit styles from small, unless you specify a different layout using the medium grid classes.

<div class="row">
  <div class="medium-2 columns">2 columns</div>
  <div class="medium-10 columns">10 columns</div>
</div>
<div class="row">
  <div class="medium-3 columns">3 columns</div>
  <div class="medium-9 columns">9 columns</div>
</div>
2 columns
10 columns
3 columns
9 columns

Advanced

Combined Column/Row

If you need a full-width column to use as a container, put the .column and .row classes on the same element. You can still nest more grids inside this container like usual.

Column rows can use sizing classes like .small-8, but only when used as a top-level container—not when nested inside another row.

<div class="column row">
  Row column
</div>
Row column

Fluid Row

Normally, a row is always 1200 pixels wide. Make a row completely fluid by adding the .expanded class.

<div class="expanded row">
</div>

Nesting

You can nest the grids indefinitely, though at a certain point it will get absurd.

<div class="row">
  <div class="small-8 columns">8
    <div class="row">
      <div class="small-8 columns">8 Nested
        <div class="row">
          <div class="small-8 columns">8 Nested Again</div>
          <div class="small-4 columns">4</div>
        </div>
      </div>
      <div class="small-4 columns">4</div>
    </div>
  </div>
  <div class="small-4 columns">4</div>
</div>
8
8 Nested
8 Nested Again
4
4
4

Offsets

Move blocks up to 11 columns to the right by using classes like .large-offset-1 and .small-offset-3.

<div class="row">
  <div class="large-1 columns">1</div>
  <div class="large-11 columns">11</div>
</div>
<div class="row">
  <div class="large-1 columns">1</div>
  <div class="large-10 large-offset-1 columns">10, offset 1</div>
</div>
<div class="row">
  <div class="large-1 columns">1</div>
  <div class="large-9 large-offset-2 columns">9, offset 2</div>
</div>
<div class="row">
  <div class="large-1 columns">1</div>
  <div class="large-8 large-offset-3 columns">8, offset 3</div>
</div>
1
11
1
10, offset 1
1
9, offset 2
1
8, offset 3

Incomplete Rows

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="row">
  <div class="medium-3 columns">3</div>
  <div class="medium-3 columns">3</div>
  <div class="medium-3 columns">3</div>
</div>
<div class="row">
  <div class="medium-3 columns">3</div>
  <div class="medium-3 columns">3</div>
  <div class="medium-3 columns end">3 end</div>
</div>
3
3
3
3
3
3 end

Gutters

Responsive gutters were added in Foundation 6.1.

The grid gutter—the space between two columns in a row, and the space between the edge of a grid and the edge of the page—is responsive, and becomes wider on larger screens.

Breakpoint Gutter Size
small 20px
medium 30px

If you're using the Sass version of Foundation, you can change these defaults by editing the $grid-column-gutter variable:

$grid-column-gutter: (
  small: 20px,
  medium: 30px,
);

To add more gutter definitions, add new lines to the map. The breakpoint names used here must match a breakpoint name in your project's $breakpoints map.

Or, if you prefer using one gutter size on every breakpoint, just use a single number.

$grid-column-gutter: 30px;

Collapse/Uncollapse Rows

The .collapse class lets you remove column gutters (padding).

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 shows no gutter at small media size and then adds the gutter to columns at medium.

<div class="row medium-uncollapse large-collapse">
  <div class="small-6 columns">
    Removes gutter at large media query
  </div>
  <div class="small-6 columns">
    Removes gutter at large media query
  </div>
</div>

Scale the browser down to a medium size to see the difference.

On a small screen, I have gutters!

On a medium screen, I have gutters!

On a large screen, I have no gutters!

On a small screen, I have gutters!

On a medium screen, I have gutters!

On a large screen, I have no gutters!


Centered Columns

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="row">
  <div class="small-3 small-centered columns">3 centered</div>
</div>
<div class="row">
  <div class="small-6 large-centered columns">6 centered</div>
</div>
<div class="row">
  <div class="small-9 small-centered large-uncentered columns">9 centered</div>
</div>
<div class="row">
  <div class="small-11 small-centered columns">11 centered</div>
</div>
3 centered
6 centered, large
9 centered small
11 centered

Source Ordering

Using these source ordering classes, you can shift columns around between our 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-#, .large-push-# is the syntax you'll use. Use the number 0 instead to reset a push/pull, such as .medium-push-0 or .large-pull-0.

<div class="row">
  <div class="small-10 small-push-2 columns">10</div>
  <div class="small-2 small-pull-10 columns">2, last</div>
</div>
<div class="row">
  <div class="large-9 large-push-3 columns">9</div>
  <div class="large-3 large-pull-9 columns">3, last</div>
</div>
<div class="row">
  <div class="large-8 large-push-4 columns">8</div>
  <div class="large-4 large-pull-8 columns">4, last</div>
</div>
<div class="row">
  <div class="small-5 small-push-7 medium-7 medium-push-5 columns">7</div>
  <div class="small-7 small-pull-5 medium-5 medium-pull-7 columns">5, last</div>
</div>
<div class="row">
  <div class="medium-6 medium-push-6 columns">6</div>
  <div class="medium-6 medium-pull-6 columns">6, last</div>
</div>
10
2, last
9
3, last
8
4, last
7
5, last
6
6, last

Block Grids

The block grid from Foundation 5 has been merged into the main grid. Add a class of the format [size]-up-[n] to change the size of all columns within the row. By default, the max number of columns you can use with block grid are 8.

<div class="row small-up-1 medium-up-2 large-up-4">
  <div class="column">
    <img src="//placehold.it/300x300" class="thumbnail" alt="">
  </div>
  <div class="column">
    <img src="//placehold.it/300x300" class="thumbnail" alt="">
  </div>
  <div class="column">
    <img src="//placehold.it/300x300" class="thumbnail" alt="">
  </div>
  <div class="column">
    <img src="//placehold.it/300x300" class="thumbnail" alt="">
  </div>
  <div class="column">
    <img src="//placehold.it/300x300" class="thumbnail" alt="">
  </div>
  <div class="column">
    <img src="//placehold.it/300x300" class="thumbnail" alt="">
  </div>
</div>

Building Semantically

Our grid CSS is generated with a powerful set of Sass mixins, which you can use in your own code to build a semantic grid.

Rows

Use the grid-row() mixin to create a row.

.container {
  @include grid-row;
}

Columns

Use the grid-column() mixin to create a column. There are a number of ways to define the width of the column.

.main-content {
  // Use the full column count (100%)
  @include grid-column;

  // Use a column count (33%);
  @include grid-column(4);

  // Use a percentage (15%)
  @include grid-column(15%);

  // Use a custom fraction (20%)
  @include grid-column(1 of 5);
}

The grid column calculator can also be accessed as a function. This gives you the percentage value, without any of the grid column CSS.

.main-content {
  width: grid-column(1 of 7);
}

To center a column semantically. Use ´grid-column-position(center);´.

.centered-column {
  @include grid-column-position(center);
}

Multiple Grids

By default, all grids use the number of columns set by the $grid-column-count variable. However, this can be selectively overridden within an instance of a row.

In this example, the grid is 16 columns instead of the normal 12. Any references to column math inside the mixin will use the new column count.

.container {
  @include grid-row(16) {
    .main-content {
      // 5/16 = 31.25%
      @include grid-column(5);
    }

    .sidebar {
      // 11/16 = 68.75%
      @include grid-column(11);
    }
  }
}

You can also temporarily change the grid context without outputting any row CSS, by using the grid-context() mixin.

@include grid-context(7) {
  .sidebar {
    @include grid-column(4);
  }
}

Every other grid feature, from sizing to offsets to source ordering, can also be accessed with a mixin. Pair them with the breakpoint() mixin to make your grid responsive.

Refer to the Sass documentation below to learn how each mixin works.

.main-content {
  // The mixins have shorthands, too!
  @include grid-col;

  @include breakpoint(medium) {
    // Changes size only
    @include grid-col-size(8);

    // Changes position only
    @include grid-col-pos(4);
  }
}

Sass Reference

Variables

The default styles of this component can be customized using these Sass variables in your project's settings file.

NameTypeDefault ValueDescription
$grid-row-width Number $global-width

The maximum width of a row.

$grid-column-count Number 12

The default column count of a grid. Changing this value affects the logic of the grid mixins, and the number of CSS classes output.

$grid-column-gutter Map or Length small: 20px
medium: 30px

The amount of space between columns at different screen sizes. To use just one size, set the variable to a number instead of a map.

$grid-column-align-edge Boolean true

If true, the last column in a row will align to the opposite edge of the row.

$block-grid-max Number 8

The highest number of .x-up classes available when using the block grid CSS.


Mixins

We use these mixins to build the final CSS output of this component. You can use the mixins yourself to build your own class structure out of our components.

grid-column

@include grid-column($columns, $gutter);

Creates a grid column.

ParameterTypeDefault ValueDescription
$columns Mixed $grid-column-count

Width of the column. Refer to the grid-column() function to see possible values.

$gutter Number $grid-column-gutter

Spacing between columns.


grid-column-row

@include grid-column-row($gutter);

Creates a grid column row. This is the equivalent of adding .row and .column to the same element.

Aliases: grid-col-row()

ParameterTypeDefault ValueDescription
$gutter Number $grid-column-gutter

Width of the gutters on either side of the column row.


grid-column-collapse

@include grid-column-collapse;

Collapse the gutters on a column by removing the padding. Note: only use this mixin within a breakpoint. To collapse a column's gutters on all screen sizes, use the $gutter parameter of the grid-column() mixin instead.

Aliases: grid-col-collapse()


grid-column-uncollapse

@include grid-column-uncollapse($gutter);

Un-collapse the gutters on a column by re-adding the padding.

Aliases: grid-col-uncollapse()

ParameterTypeDefault ValueDescription
$gutter Number $grid-column-gutter

Spacing between columns.


grid-layout

@include grid-layout($n, $selector);

Sizes child elements so that $n number of items appear on each row.

ParameterTypeDefault ValueDescription
$n Number None

Number of elements to display per row.

$selector String '.column'

Selector(s) to use for child elements.


grid-layout-center-last

@include grid-layout-center-last($n);

Adds extra CSS to block grid children so the last items in the row center automatically. Apply this to the columns, not the row.

ParameterTypeDefault ValueDescription
$n Number None

Number of items that appear in each row.


grid-column-position

@include grid-column-position($position);

Reposition a column.

Aliases: grid-col-pos()

ParameterTypeDefault ValueDescription
$position Number or Keyword None

Direction and amount to move. The column will move equal to the width of the column count specified. A positive number will push the column to the right, while a negative number will pull it to the left. Set to center to center the column.


grid-column-unposition

@include grid-column-unposition;

Reset a position definition.

Aliases: grid-col-unpos()


grid-column-offset

@include grid-column-offset($n);

Offsets a column to the right by $n columns.

Aliases: grid-col-off()

ParameterTypeDefault ValueDescription
$n Number or List None

Width to offset by. You can pass in any value accepted by the grid-column() mixin, such as 6, 50%, or 1 of 2.


grid-column-end

@include grid-column-end;

Disable the default behavior of the last column in a row aligning to the opposite edge.

Aliases: grid-col-end()


grid-context

@include grid-context($columns, $root) { }

Change the behavior of columns defined inside this mixin to use a different column count.

ParameterTypeDefault ValueDescription
$columns Number None

Number of columns to use.

$root Boolean false

If false, selectors inside this mixin will nest inside the parent selector. If true, selectors will not nest.


grid-row

@include grid-row($columns, $behavior, $width, $cf, $gutter) { }

Creates a grid row.

ParameterTypeDefault ValueDescription
$columns Number null

Column count for this row. null will use the default column count.

$behavior Keywords null

Modifications to the default grid styles. nest indicates the row will be placed inside another row. collapse indicates that the columns inside this row will not have padding. nest collapse combines both behaviors.

$width Number $grid-row-width

Maximum width of the row.

$cf Boolean true

Whether or not to include a clearfix.

$gutter Number $grid-column-gutter

Gutter to use when inverting margins, in case the row is nested.


grid-row-nest

@include grid-row-nest($gutter);

Inverts the margins of a row to nest it inside of a column.

ParameterTypeDefault ValueDescription
$gutter Map or null null

Gutter value to use when inverting the margins. Set to null to refer to the responsive gutter settings.


grid-column-size

@include grid-column-size($width);

Set the width of a grid column.

Aliases: grid-col-size()

ParameterTypeDefault ValueDescription
$width Number or List $grid-column-count

Width to make the column. You can pass in any value accepted by the grid-column() function, such as 6, 50%, or 1 of 2.



Functions

grid-column

grid-column($columns)

Calculates the width of a column based on a number of factors.

ParameterTypeDefault ValueDescription
$columns Number or List None

Width of the column. Accepts multiple values:

  • A percentage value will make the column that exact size.
  • A single digit will make the column span that number of columns wide, taking into account the column count of the parent row.
  • A string of the format "x of y" will make a column that is x columns wide, assuming y total columns for the parent.

Stay on top of what’s happening in responsive design.

Sign up to receive monthly Responsive Reading highlights. Read Last Month's Edition »