Utilities

Grid

The SLDS grid system provides a flexible, mobile-first, device-agnostic layout system. It has features to control alignment, order, flow, and gutters.

About Grids#

Our most-used grid has standard 16px gutters. If you don’t have a design that calls for something more specific, this is the grid you’ll want to use. We’ll also show you exactly how to customize it for your use-case.

To build a grid:

  1. Add a grid container by adding slds-grid to an HTML element
  2. Add as many slds-col elements as you want inside of your grid container
1
2
3
<div class="slds-grid slds-gutters">
  <div class="slds-col">
    <span>1</span>
  </div>

Initially, each column takes an equal percentage of the width available. In this case, that's 33.3% of the container’s width. Once content is added, the sections expand as needed to fit the content if sizing classes are not used.

1
2
3
4
<div class="slds-grid slds-gutters">
  <div class="slds-col">
    <span>1</span>
  </div>

Adding a fourth column means they'll each take up 25% of the width of the container.

12 Column Support#

You can have up to 12 columns in your grid.

1
2
3
4
5
6
7
8
9
10
11
12
<div class="slds-grid">
  <div class="slds-col">
    <span>1</span>
  </div>

Column Widths#

If you don’t want the columns to have widths based on their content, you can easily control the width of the columns by adding column width classes.

1
2
<div class="slds-grid slds-gutters">
  <div class="slds-col slds-size_2-of-3">
    <span>1</span>
  </div>

This example sets the width of the first column 66% of your slds-grid container and the second column to 33% of your slds-grid container.

Tip

Our sizing classes set widths in percentages. This will keep your layout fluid to the width of your slds-grid container.

A 12 column grid is our most used grid. Here's an overview of all the available width classes for a 12 column grid:

1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
3
3
3
3
4
4
4
5
5
2
6
6
7
5
8
4
9
3
10
2
11
1
<div class="slds-grid slds-wrap">
  <div class="slds-col slds-size_1-of-12">
    <span>1</span>
  </div>

Since width class names are written in a human-friendly way, you may choose to write slds-size_1-of-2 or slds-size_6-of-12, both outcomes are the same.

1/6
1/6
1/6
1/6
1/6
1/6
1/4
1/4
1/4
1/4
1/3
1/3
1/3
1/2
1/2
1/1
<div class="slds-grid slds-wrap">
  <div class="slds-col slds-size_1-of-6">
    <span>1/6</span>
  </div>

Column Gutters#

By default, we start with 0 gutters on our columns. This allows flexibility to add gutter widths of your liking to each column(s) or grid container.

You can easily add padding to your grid by applying slds-gutters to the slds-grid container. This will add the gutters to your columns as well as align the outside of your grid.

1
2
<div class="slds-grid slds-gutters">
  <div class="slds-col">
    <span>1</span>
  </div>

In the above example, adding slds-gutters will give us our default gutter size of 24px (12px on each side).

The default slds-gutters is subject to change over time but is a great way to ensure when we upgrade, you upgrade.

You can modify the width of the gutters between each column by using slds-gutters_x-small (16px), slds-gutters_small (24px), slds-gutters_medium (32px), slds-gutters_large (48px), and slds-gutters_x-large (64px).

You can also add different gutter widths to your columns by using a spacing utility and adding it to the slds-col element (e.g. slds-p-location_size-*). The "location" can be left, right, top, bottom, vertical, horizontal or around. The "size" can be xxx-small (2px), xx-small (4px), x-small (8px), small (12px), medium (16px), large (24px), x-large (32px) or xx-large (48px).

1
2
<div class="slds-grid">
  <div class="slds-col slds-p-horizontal_medium">
    <span>1</span>
  </div>

The above example adds gutters of 32px (16px on each side) in between each column.

You'll notice the 16px space on the left and right of your container created by the spacing classes. You can remove this by adding a slds-grid_pull-padded-[size] class to the slds-grid container. The [size] portion of this class should be the name of the spacing utility size you've applied to the outermost columns.

1
2
<div class="slds-grid slds-grid_pull-padded-medium">
  <div class="slds-col slds-p-horizontal_medium">
    <span>1</span>
  </div>

Direct Columns Only#

By default, slds-gutters will apply to any column nested within the grid. If you only want direct child columns to receive gutters, use the slds-gutters_direct class.

You can modify the width of the gutters between each column by using slds-gutters_direct-x-small (16px), slds-gutters_direct-small (24px), slds-gutters_direct-medium (32px), slds-gutters_direct-large (48px), and slds-gutters_direct-x-large (64px).

1
Nested Column 1
Nested Column 2
3
<div class="slds-grid slds-gutters_direct">
  <div class="slds-col">
    <span>1</span>
  </div>

Below is the same example without using the slds-gutters_direct class:

1
Nested Column 1
Nested Column 2
3
<div class="slds-grid slds-gutters">
  <div class="slds-col">
    <span>1</span>
  </div>

Column Wrapping#

By default, your columns will align themselves horizontally unless you tell them otherwise. If you are using sizing classes (e.g. slds-size_4-of-12) and the total # of columns in a row exceed 12 then you can let the grid container know to wrap your columns to a new row by adding slds-wrap to the slds-grid container.

1
1
1
<div class="slds-grid slds-wrap">
  <div class="slds-col slds-size_8-of-12">
    <span>1</span>
  </div>

Column Reordering#

Accessibility concern

You can visually reorder columns independently from their position in the markup, but you should avoid doing so if you wish to remain WCAG compliant.

1
2
3
<div class="slds-grid">
  <div class="slds-col slds-order_3">
    <span>1</span>
  </div>

Column Nesting#

Nesting columns is simple and can add more flexibility in your designs. In a column, you can add a nested grid by creating another slds-grid container and as many slds-col elements inside of that container as you need.

1
Nested: 1
Nested: 2
<div class="slds-grid slds-wrap">
  <div class="slds-col slds-size_10-of-12">
    <span>1</span>
  </div>

Grid Flow#

Once an slds-grid has been set, you can change things like flow. By default, a grid flows left to right on the main horizontal axis. You can easily switch your grid to flow top to bottom on a vertical axis by adding slds-grid_vertical to the slds-grid container.

Left to Right#

The default flow is left to right on the horizontal axis

1
2
3
<div class="slds-grid">
  <div class="slds-col">
    <span>1</span>
  </div>

Top to Bottom#

To switch the grid to flow top to bottom on the vertical axis, add slds-grid_vertical to the slds-grid container.

1
2
3
<div class="slds-grid slds-grid_vertical">
  <div class="slds-col">
    <span>1</span>
  </div>

Reversed#

There may be times you find yourself in a situation to reverse the visual flow of your columns. You can do this both horizontally and vertically.

Right to Left#

To reverse the horizontal flow, add the class slds-grid_reverse to the slds-grid container.

1
2
3
<div class="slds-grid slds-grid_reverse">
  <div class="slds-col">
    <span>1</span>
  </div>

Bottom to Top#

To reverse the vertical flow, add the class slds-grid_vertical-reverse to the slds-grid container.

1
2
3
<div class="slds-grid slds-grid_vertical-reverse" style="height:200px">
  <div class="slds-col">
    <span>1</span>
  </div>

Creating Responsive Layouts#

The SLDS grid system can become responsive to your viewport size by prefixing our sizing and ordering classes with a breakpoint name. Our responsive sizing utilities are built upon a mobile first approach.

To achieve the desired outcome of this approach, you will need to append responsive sizing utilities to an element that override the previous breakpoint.

This means the sizing utility used will start at the smallest width and continue to be applied until a responsive sizing utility for a specific breakpoint overrides it.

In some uncommon cases, you may need a sizing utility that is up to a certain breakpoint. For these, use the classes prefixed with max- to achieve this result.

Responsive Layout Options#

Below is an overview table outlining the default behavior for columns and how that behavior may change for responsive breakpoints.

DefaultSmall (>= 480px)Medium (>=768px)Large (>=1024px)
Width class prefixslds-sizeslds-small-sizeslds-medium-sizeslds-large-size
# of columns1,2,3,4,5,6,7,8 and 12
Column ordering prefixslds-orderslds-small-orderslds-medium-orderslds-large-order
Max # of reorders12

Note: To make sure columns wrap as they exceed a total column count of 12, responsive layouts require slds-wrap to be added to the slds-grid container.

Mobile/Desktop Example#

Since we build on the concept of mobile first, let's set a layout for mobile and override for desktop directly in our HTML. We do this by setting a mobile, in this case default widths to our columns and override the layout when we meet the criteria of a desktop viewport size.

1
2
<div class="slds-grid slds-wrap">
  <div class="slds-col slds-size_1-of-1 slds-large-size_8-of-12">
    <span>1</span>
  </div>

In the above example, we are setting a stacked layout for mobile/tablet devices and then when our viewport exceeds a width of 1024px we redraw our layout to be a nice two column where the primary content area takes up 8 columns and the secondary content area takes up 4 columns.

Mobile/Tablet/Desktop Example#

If our designs need a bit more flexibility, we can accomplish that by establishing different layouts for mobile, tablet, and desktop.

1
2
<div class="slds-grid slds-wrap">
  <div class="slds-col slds-size_1-of-1 slds-medium-size_6-of-12 slds-large-size_8-of-12">
    <span>1</span>
  </div>

In this above example, we are setting our default stacked layout and when our browser exceeds a viewport width of 768px, we adjust the layout for each column to take up 50% or 6 columns of the slds-grid container. Then once we exceed a viewport width of 1024px, we again redraw a layout to be a nice 66% or 8 columns for the primary content area and 33% or 4 columns for the secondary content area.

Conditional Column Reordering#

With flexbox it's easy to reorder your columns visually. Luckily with the SLDS grid system it's easy to reorder visually in a responsive manner! Following the same naming convention as sizing, we'll want to prefix slds-order with our breakpoint name and pass in an integer for where you want it visually. The lowest value is the first in order. If no order is defined, standard ordering is applied. This means that a column with no order class will render before slds-order_1.

1
2
<div class="slds-grid">
  <div class="slds-col slds-order_2 slds-large-order_1">
    <span>1</span>
  </div>

In the above example, we're setting our first column to be last in the order of 3. Then once your viewport exceeds a width of 1024px, we're changing the visual order of our first column back to 1. Now this seemed rather long winded to move 1 column. Below is an easy way of letting the column know you only want to reorder the first column if it's in a viewport smaller than 480px. This breaks the convention of mobile first and should be used sparingly.

Alignment#

Since the grids are built on flexbox, they allow us to do some interesting things with alignment on both a horizontal axis and vertical axis. You can add an alignment utility to the slds-grid container.

Horizontal Axis#

Content centered#

If you want your columns to grow from the the center of the horizontal axis, apply the class slds-grid_align-center.

1
2
3
<div class="slds-grid slds-grid_align-center">
  <div class="slds-col">
    <span>1</span>
  </div>

Setting variable widths based on content#

Another powerful technique is letting a column shrink to the width of the content inside of it, while explicitly setting widths to other columns. This is achieved by using the slds-shrink-none or slds-grow-none utility classes or simply removing the slds-col class from the column element.

1
2
3
<div class="slds-grid slds-grid_align-center">
  <div class="slds-col slds-size_1-of-6">
    <span>1</span>
  </div>

Content evenly spaced out#

To evenly distribute columns on the horizontal axis with an equal amount of white space separating the columns, apply the class slds-grid_align-space.

1
2
3
<div class="slds-grid slds-grid_align-space">
  <div class="slds-col">
    <span>1</span>
  </div>

Content evenly spread out from edges#

To spread out your columns on the horizontal axis, with the first column starting at the start of your main axis and last item ending at the far end of your main axis, apply the class slds-grid_align-spread.

1
2
3
<div class="slds-grid slds-grid_align-spread">
  <div class="slds-col">
    <span>1</span>
  </div>

Content right justified#

If you want your columns to grow from the end of the horizontal axis, apply the class slds-grid_align-end.

1
2
3
<div class="slds-grid slds-grid_align-end">
  <div class="slds-col">
    <span>1</span>
  </div>

Content alignment with bump#

To "bump" a single or multiple grid items, apply the class slds-col_bump-{direction}, with {direction} being either left, right, top or bottom, to a grid item.

Bump Left

In the example below, applying the left bump class to item 5 bumps items 1 through 4 to the left.

1
2
3
4
5
6
<div class="slds-grid">
  <div>
    <span>1</span>
  </div>

Bump Right

In the example below, applying the right bump class to item 5 bumps item 6 to the right.

1
2
3
4
5
6
<div class="slds-grid">
  <div>
    <span>1</span>
  </div>

Vertical Axis#

Implementation Note

To vertically align elements on a cross-axis of a `slds-grid` container, the elements need available vertical white space. This is usually achieved by having a height applied to the `slds-grid` container.

Content top#

To align a single row or multi-line rows to the beginning of the cross axis, apply the class slds-grid_vertical-align-start.

1
2
3
<div class="slds-grid slds-grid_vertical-align-start">
  <div class="slds-col">
    <span>1</span>
  </div>

Content centered#

To vertically center align a single row or multi-line rows to the height of a slds-grid container, apply the class slds-grid_vertical-align-center. When slds-grid_vertical-align-center is used in conjunction with slds-grid_align-center, the outcome would horizontally and vertically center align your content in the center of the slds-grid container.

1
2
3
<div class="slds-grid slds-grid_vertical-align-center">
  <div class="slds-col">
    <span>1</span>
  </div>

Content bottom#

To align a single row or multi-line rows to the end of the cross axis, apply the class slds-grid_vertical-align-end.

1
2
3
<div class="slds-grid slds-grid_vertical-align-end">
  <div class="slds-col">
    <span>1</span>
  </div>

Content absolutely centered#

1
2
3
<div class="slds-grid slds-grid_vertical-align-center slds-grid_align-center">
  <div class="slds-col">
    <span>1</span>
  </div>

Individual alignment#

To specify the vertical placement of grid items on the cross axis, you can apply slds-align-top, slds-align-middle, and slds-align-bottom to a slds-col element.

1
2
3
<div class="slds-grid">
  <div class="slds-col slds-align-top">
    <span>1</span>
  </div>

Page Containers#

Optionally, you can contain your page content by adding the class slds-container_width to a top level element in your page structure.

Containers come in 4 widths, small, medium, large and x-large. They are rendered using max-width. This means your content will be a fluid width until it reaches the width the modifier has set on the container.

ClassWidth
slds-container_small480px
slds-container_medium768px
slds-container_large1024px
slds-container_x-large1280px

Additionally, you can center the content of your page by adding slds-container_center.

Overview of CSS Classes#

Selector.slds-grid
Summary

Initializes grid

Restrict*
ModifierTrue
Selector.slds-grid_frame
Summary

Initializes grid

Restrict*
ModifierTrue
Selector.slds-grid_vertical
Summary

Initializes grid

Restrict*
ModifierTrue
Selector.slds-grid_vertical-reverse
Summary

Initializes grid

Restrict*
ModifierTrue
Selector.slds-grid_reverse
Summary

Initializes grid

Restrict*
ModifierTrue
Selector.slds-wrap
Summary

Allows columns to wrap when they exceed 100% of their parent’s width

Restrict*
ModifierTrue
Selector.slds-nowrap
Summary

Keeps columns on one line. Allows columns to stretch and fill 100% of the parent’s width and height.

Restrict*
ModifierTrue
Selector.slds-gutters
Summary

Apply 12px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_xxx-small
Summary

Apply 2px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_xx-small
Summary

Apply 4px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_x-small
Summary

Apply 8px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_small
Summary

Apply 12px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_medium
Summary

Apply 16px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_large
Summary

Apply 24px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_x-large
Summary

Apply 32px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_xx-large
Summary

Apply 48px gutters to each grid column when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct
Summary

Apply 12px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-xxx-small
Summary

Apply 2px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-xx-small
Summary

Apply 4px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-x-small
Summary

Apply 8px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-small
Summary

Apply 12px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-medium
Summary

Apply 16px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-large
Summary

Apply 24px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-x-large
Summary

Apply 32px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-gutters_direct-xx-large
Summary

Apply 48px gutters to only direct column children when you add this class to an slds-grid element

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded
Summary

Normalizes the 0.75rem of padding when nesting a grid in a region with .slds-p-horizontal_small

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-xxx-small
Summary

Normalizes the 0.125rem of padding when nesting a grid in a region with .slds-p-horizontal_xxx-small

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-xx-small
Summary

Normalizes the 0.25rem of padding when nesting a grid in a region with .slds-p-horizontal_xx-small

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-x-small
Summary

Normalizes the 0.5rem of padding when nesting a grid in a region with .slds-p-horizontal_x-small

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-small
Summary

Normalizes the 0.75rem of padding when nesting a grid in a region with .slds-p-horizontal_small

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-medium
Summary

Normalizes the 1rem of padding when nesting a grid in a region with .slds-p-horizontal_medium

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-large
Summary

Normalizes the 1.5rem of padding when nesting a grid in a region with .slds-p-horizontal_large

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-x-large
Summary

Normalizes the 1.5rem of padding when nesting a grid in a region with .slds-p-horizontal_x-large

Restrict*
ModifierTrue
Selector.slds-grid_pull-padded-xx-large
Summary

Normalizes the 1.5rem of padding when nesting a grid in a region with .slds-p-horizontal_xx-large

Restrict*
ModifierTrue
Selector.slds-col
Summary

Initializes a grid column

Restrict*
ModifierTrue
Selector.slds-has-flexi-truncate
Summary

Needed when truncation is nested in a flexible container in a grid

Restrict*
ModifierTrue
Selector.slds-no-flex
Summary

Removes flexbox from grid column

Restrict*
ModifierTrue
Selector.slds-no-space
Summary

Sets the column to a min-width of 0

Restrict*
ModifierTrue
Selector.slds-grow
Summary

Allows column to grow to children’s content

Restrict*
ModifierTrue
Selector.slds-grow-none
Summary

Prevents column from growing to children’s content

Restrict*
ModifierTrue
Selector.slds-shrink
Summary

Allows column to shrink to children's content

Restrict*
ModifierTrue
Selector.slds-shrink-none
Summary

Prevents column from shrinking to children's content

Restrict*
ModifierTrue
Selector.slds-grid_align-center
Summary

Columns align in the center to the main axis and expand in each direction

Restrict*
ModifierTrue
Selector.slds-grid_align-space
Summary

Columns are evenly distributed with equal space around them all

Restrict*
ModifierTrue
Selector.slds-grid_align-spread
Summary

Columns align to the left and right followed by center. Space is equal between them

Restrict*
ModifierTrue
Selector.slds-grid_align-end
Summary

Columns start on the opposite end of the grid's main axis

Restrict*
ModifierTrue
Selector.slds-grid_vertical-align-start
Summary

Columns start at the beginning of the grid's cross axis

Restrict*
ModifierTrue
Selector.slds-grid_vertical-align-center
Summary

Columns align in the center to the cross axis and expand it each direction

Restrict*
ModifierTrue
Selector.slds-grid_vertical-align-end
Summary

Columns start on the opposite end of the grid's cross axis

Restrict*
ModifierTrue
Selector.slds-col_bump-top
Summary

Bumps grid item(s) away from the other grid items to sit at the top, taking up the remaining white-space of the grid container

Restrict*
ModifierTrue
Selector.slds-col_bump-right
Summary

Bumps grid item(s) away from the other grid items to sit to the right, taking up the remaining white-space of the grid container

Restrict*
ModifierTrue
Selector.slds-col_bump-bottom
Summary

Bumps grid item(s) away from the other grid items to sit at the bottom, taking up the remaining white-space of the grid container

Restrict*
ModifierTrue
Selector.slds-col_bump-left
Summary

Bumps grid item(s) away from the other grid items to sit to the left, taking up the remaining white-space of the grid container

Restrict*
ModifierTrue
Selector.slds-grid_vertical-stretch
Summary

Stretch the grid items for both single row and multi-line rows to fill the height of the parent grid container

Restrict*
ModifierTrue
Selector.slds-container_small
Summary

Restrict width of containers to a maximum of 480px

Restrict*
ModifierTrue
Selector.slds-container_medium
Summary

Restrict width of containers to a maximum of 768px

Restrict*
ModifierTrue
Selector.slds-container_large
Summary

Restrict width of containers to a maximum of 1024px

Restrict*
ModifierTrue
Selector.slds-container_x-large
Summary

Restrict width of containers to a maximum of 1280px

Restrict*
ModifierTrue
Selector.slds-container_fluid
Summary

Width of container takes up 100% of viewport

Restrict*
ModifierTrue
Selector.slds-container_center
Summary

Horizontally positions containers in the center of the viewport

Restrict*
ModifierTrue
Selector.slds-container_left
Summary

Horizontally positions containers to the left of the viewport

Restrict*
ModifierTrue
Selector.slds-container_right
Summary

Horizontally positions containers to the right of the viewport

Restrict*
ModifierTrue

Grid Release Notes

2.7.0

Added

  • Added slds-gutters_direct for adding gutters to direct child columns of a grid.

Fixed

  • Updated slds-col_bump-bottom to accurately set margin-bottom, instead of margin-right, to auto.