Grid
- HTML/CSS:Dev Ready
- Layout:Responsive
Sections
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:
- Add a grid container by adding
slds-grid
to an HTML element - Add as many
slds-col
elements as you want inside of your grid container
<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.
<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.
<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.
<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:
<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.
<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.
<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).
<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.
<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).
<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:
<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.
<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.
<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.
<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
<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.
<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.
<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.
<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.
Default | Small (>= 480px) | Medium (>=768px) | Large (>=1024px) | |
---|---|---|---|---|
Width class prefix | slds-size | slds-small-size | slds-medium-size | slds-large-size |
# of columns | 1,2,3,4,5,6,7,8 and 12 | |||
Column ordering prefix | slds-order | slds-small-order | slds-medium-order | slds-large-order |
Max # of reorders | 12 |
Note: To make sure columns wrap as they exceed a total column count of 12, responsive layouts require
slds-wrap
to be added to theslds-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.
<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.
<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
.
<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
.
<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.
<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
.
<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
.
<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
.
<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.
<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.
<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
.
<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.
<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
.
<div class="slds-grid slds-grid_vertical-align-end">
<div class="slds-col">
<span>1</span>
</div>
Content absolutely centered#
<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.
<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.
Class | Width |
---|---|
slds-container_small | 480px |
slds-container_medium | 768px |
slds-container_large | 1024px |
slds-container_x-large | 1280px |
Additionally, you can center the content of your page by adding slds-container_center
.
Overview of CSS Classes#
- Selector
- The CSS class being referred to.
- Summary
- A description of what the class does.
- Support
- Whether the class name is dev-ready (meaning it's fully vetted and tested and safe to use) or prototype (which means it's not fully vetted yet).
- Restrict
- The selector that the class name is allowed to be used on.
- Variant
- The base level pattern for a component. A variant can be extended to create another variant of that component, for example, a stateful button is a derivative of the base button.
- Modifier
- A single class that can be added to an HTML element of a component to modify its output. Typically these will be colors, sizing and positioning.
Selector | .slds-grid |
---|---|
Summary | Initializes grid |
Restrict | * |
Modifier | True |
Selector | .slds-grid_frame |
---|---|
Summary | Initializes grid |
Restrict | * |
Modifier | True |
Selector | .slds-grid_vertical |
---|---|
Summary | Initializes grid |
Restrict | * |
Modifier | True |
Selector | .slds-grid_vertical-reverse |
---|---|
Summary | Initializes grid |
Restrict | * |
Modifier | True |
Selector | .slds-grid_reverse |
---|---|
Summary | Initializes grid |
Restrict | * |
Modifier | True |
Selector | .slds-wrap |
---|---|
Summary | Allows columns to wrap when they exceed 100% of their parent’s width |
Restrict | * |
Modifier | True |
Selector | .slds-nowrap |
---|---|
Summary | Keeps columns on one line. Allows columns to stretch and fill 100% of the parent’s width and height. |
Restrict | * |
Modifier | True |
Selector | .slds-gutters |
---|---|
Summary | Apply 12px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_xxx-small |
---|---|
Summary | Apply 2px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_xx-small |
---|---|
Summary | Apply 4px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_x-small |
---|---|
Summary | Apply 8px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_small |
---|---|
Summary | Apply 12px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_medium |
---|---|
Summary | Apply 16px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_large |
---|---|
Summary | Apply 24px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_x-large |
---|---|
Summary | Apply 32px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_xx-large |
---|---|
Summary | Apply 48px gutters to each grid column when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct |
---|---|
Summary | Apply 12px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-xxx-small |
---|---|
Summary | Apply 2px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-xx-small |
---|---|
Summary | Apply 4px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-x-small |
---|---|
Summary | Apply 8px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-small |
---|---|
Summary | Apply 12px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-medium |
---|---|
Summary | Apply 16px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-large |
---|---|
Summary | Apply 24px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-x-large |
---|---|
Summary | Apply 32px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-gutters_direct-xx-large |
---|---|
Summary | Apply 48px gutters to only direct column children when you add this class to an |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded |
---|---|
Summary | Normalizes the 0.75rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-xxx-small |
---|---|
Summary | Normalizes the 0.125rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-xx-small |
---|---|
Summary | Normalizes the 0.25rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-x-small |
---|---|
Summary | Normalizes the 0.5rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-small |
---|---|
Summary | Normalizes the 0.75rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-medium |
---|---|
Summary | Normalizes the 1rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-large |
---|---|
Summary | Normalizes the 1.5rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-x-large |
---|---|
Summary | Normalizes the 1.5rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-grid_pull-padded-xx-large |
---|---|
Summary | Normalizes the 1.5rem of padding when nesting a grid in a region with |
Restrict | * |
Modifier | True |
Selector | .slds-col |
---|---|
Summary | Initializes a grid column |
Restrict | * |
Modifier | True |
Selector | .slds-has-flexi-truncate |
---|---|
Summary | Needed when truncation is nested in a flexible container in a grid |
Restrict | * |
Modifier | True |
Selector | .slds-no-flex |
---|---|
Summary | Removes flexbox from grid column |
Restrict | * |
Modifier | True |
Selector | .slds-no-space |
---|---|
Summary | Sets the column to a min-width of 0 |
Restrict | * |
Modifier | True |
Selector | .slds-grow |
---|---|
Summary | Allows column to grow to children’s content |
Restrict | * |
Modifier | True |
Selector | .slds-grow-none |
---|---|
Summary | Prevents column from growing to children’s content |
Restrict | * |
Modifier | True |
Selector | .slds-shrink |
---|---|
Summary | Allows column to shrink to children's content |
Restrict | * |
Modifier | True |
Selector | .slds-shrink-none |
---|---|
Summary | Prevents column from shrinking to children's content |
Restrict | * |
Modifier | True |
Selector | .slds-grid_align-center |
---|---|
Summary | Columns align in the center to the main axis and expand in each direction |
Restrict | * |
Modifier | True |
Selector | .slds-grid_align-space |
---|---|
Summary | Columns are evenly distributed with equal space around them all |
Restrict | * |
Modifier | True |
Selector | .slds-grid_align-spread |
---|---|
Summary | Columns align to the left and right followed by center. Space is equal between them |
Restrict | * |
Modifier | True |
Selector | .slds-grid_align-end |
---|---|
Summary | Columns start on the opposite end of the grid's main axis |
Restrict | * |
Modifier | True |
Selector | .slds-grid_vertical-align-start |
---|---|
Summary | Columns start at the beginning of the grid's cross axis |
Restrict | * |
Modifier | True |
Selector | .slds-grid_vertical-align-center |
---|---|
Summary | Columns align in the center to the cross axis and expand it each direction |
Restrict | * |
Modifier | True |
Selector | .slds-grid_vertical-align-end |
---|---|
Summary | Columns start on the opposite end of the grid's cross axis |
Restrict | * |
Modifier | True |
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 | * |
Modifier | True |
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 | * |
Modifier | True |
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 | * |
Modifier | True |
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 | * |
Modifier | True |
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 | * |
Modifier | True |
Selector | .slds-container_small |
---|---|
Summary | Restrict width of containers to a maximum of 480px |
Restrict | * |
Modifier | True |
Selector | .slds-container_medium |
---|---|
Summary | Restrict width of containers to a maximum of 768px |
Restrict | * |
Modifier | True |
Selector | .slds-container_large |
---|---|
Summary | Restrict width of containers to a maximum of 1024px |
Restrict | * |
Modifier | True |
Selector | .slds-container_x-large |
---|---|
Summary | Restrict width of containers to a maximum of 1280px |
Restrict | * |
Modifier | True |
Selector | .slds-container_fluid |
---|---|
Summary | Width of container takes up 100% of viewport |
Restrict | * |
Modifier | True |
Selector | .slds-container_center |
---|---|
Summary | Horizontally positions containers in the center of the viewport |
Restrict | * |
Modifier | True |
Selector | .slds-container_left |
---|---|
Summary | Horizontally positions containers to the left of the viewport |
Restrict | * |
Modifier | True |
Selector | .slds-container_right |
---|---|
Summary | Horizontally positions containers to the right of the viewport |
Restrict | * |
Modifier | True |
Grid Release Notes
2.7.0
Added
- Added
slds-gutters_direct
for adding gutters to direct child columns of a grid.- See the Direct Columns Only section for more info.
Fixed
- Updated
slds-col_bump-bottom
to accurately set margin-bottom, instead of margin-right, to auto.