A grid provides a structure of rows and columns for aligning content. Grids are useful because they help create a familiar and easily navigable structure for content.
Clarity extends the 12-column Bootstrap 4 Flex Grid and prefixes the grid classes with clr-. Prefixing allows us to avoid conflicting with other grid systems. However, it also means if you are familiar with the grid classes in Bootstrap 4, the Clarity grid will be familiar.
Important features about the grid are listed below:
Horizontal for extra-small. All other breakpoints are collapsed to start, then horizontal above the breakpoint.
- Number of columns: 12
- Gutter width: 24px (12px on the left and right of column)
- All columns support nesting, offsets, and column order
Extra small |
Extra large |
.clr-row is a horizontal group of 12 columns.
The column classes specify the number of columns per row. The value appended to the class prefix must be between 1 and 12.
Grid columns can occupy different widths on different device sizes.
In the example below, if the device size is ≥ 768px (medium or above), the grid has two columns of equal width and a third column that occupies the entire width of the row. For device sizes < 768px, each column occupies the entire width of the row and the columns are stacked. Resize your browser to see how this works.
Placing more than 12 columns in a single row will wrap the columns exceeding the row, as one unit, onto a new line.
.clr-col-* class divides the row into equal width columns.
A specific width can be assigned to a column. All the siblings of that columns will automatically resize around it.
.clr-col-*-auto class on a column sizes it based on the width of its content.
.clr-break-row class after a column, breaks the following columns to a new line.
clr-offset-* classes increase a column’s left margin by * number of columns.
Columns within a row can be vertically aligned using the following responsive classes:
A column can individually be vertically aligned in a row using the following responsive classes:
To align columns horizontally within a row, extend the row with one of the following responsive classes:
Clarity recommends that your application layout stay on the grid. A grid-based approach:
- Aligns content consistently
- Establishes a foundation that can be easily built upon for future designs
- Simplifies layout decisions required of a designer
- Coordinates the efforts of multiple designers
Apply the grid with consideration of content. Some pages might benefit from a three-column layout, where other pages might work best with a two-column layout.
You can vary the column layout within the same page. This strategy works well for presenting content that scrolls vertically.
Don’t lock your design into a layout optimized for a large window.
Designing to a grid is especially important for card layouts. Cards contains blocks of content and their height and width can vary. The grid aligns the cards in a way that is easy for users to navigate.
If You Decide Not to Conform to the Grid Do so with intent. Find a balance between aesthetics and conformity. Keep in mind that elements that are not aligned to the grid draw attention in the same way as color, contrast, and iconography and require more cognitive effort on the part of the user.