Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, six default responsive tiers, Sass variables and mixins, and dozens of predefined classes.
Example
CoreUI’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with flexbox in new window and is fully responsive. Below is an example and an in-depth explanation for how the grid system comes together.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid',
templateUrl: './grid.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridComponent {}<c-container>
<c-row>
<c-col>One of three columns</c-col>
<c-col>One of three columns</c-col>
<c-col>One of three columns</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}The above example creates three equal-width columns across all devices and viewports using our predefined grid
classes. Those columns are centered in the page with the parent c-container.
How it works
Breaking it down, here’s how the grid system comes together:
- Our grid supports six responsive breakpoints. Breakpoints are based on
min-widthmedia queries, meaning they affect that breakpoint and all those above it (e.g.,[sm]="4"applies tosm,md,lg,xl, andxxl). This means you can control container and column sizing and behavior by each breakpoint. - Containers center and horizontally pad your content. Use
c-containerfor a responsive pixel width,c-container fluidforwidth: 100%across all viewports and devices, or a responsive container (e.g.,c-container breakpoint="md") for a combination of fluid and pixel widths. - Rows are wrappers for columns. Each column has horizontal
padding(called a gutter) for controlling the space between them. Thispaddingis then counteracted on the rows with negative margins to ensure the content in your columns is visually aligned down the left side. Rows also support modifier classes to uniformly apply column sizing and gutter classes to change the spacing of your content. - Columns are incredibly flexible. There are 12 template columns available per row, allowing you to create
different combinations of elements that span any number of columns. Column classes indicate the number of template
columns to span (e.g.,
c-col [xs]="4"spans four). Widths are set in percentages so you always have the same relative sizing. - Gutters are also responsive and customizable. Gutter classes
are available across all breakpoints, with all the
same sizes as our margin and padding spacing. Change horizontal gutters
with
.gx-*classes, vertical gutters with.gy-*, or all gutters with.g-*classes..g-0is also available to remove gutters.
Be aware of the limitations and bugs around flexbox, like the inability to use some HTML elements as flex containers.
Grid options
CoreUI grid system can adapt across all six default breakpoints, and any breakpoints you customize. The six default grid tiers are as follow:
- Extra small (
xs) - Small (
sm) - Medium (
md) - Large (
lg) - Extra large (
xl) - Extra extra large (
xxl)
As noted above, each of these breakpoints have their own container, unique class prefix, and modifiers. Here’s how the grid changes across these breakpoints:
| xs <576px | sm ≥576px | md ≥768px | lg ≥992px | xl ≥1200px | xxl ≥1400px | |
|---|---|---|---|---|---|---|
Container max-width | None | 540px | 720px | 960px | 1140px | 1320px |
| Class prefix | <c-col xs=> | <c-col sm=> | <c-col md=> | <c-col lg=> | <c-col xl=> | <c-col xxl=> |
| # of columns | 12 | |||||
| Gutter width | 1.5rem (.75rem on left and right) | |||||
| Custom gutters | Yes | |||||
| Nestable | Yes | |||||
| Column ordering | Yes | |||||
Auto-layout columns
Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like c-col sm="6".
Equal-width
For example, here are two grid layouts that apply to every device and viewport, from xs to xxl. Add any number of
unit-less classes for each breakpoint you need and every column will be the same width.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-equal-width',
templateUrl: './grid-equal-width.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridEqualWidthComponent {}<c-container>
<c-row>
<c-col>1 of 2</c-col>
<c-col>2 of 2</c-col>
</c-row>
<c-row>
<c-col>1 of 3</c-col>
<c-col>2 of 3</c-col>
<c-col>3 of 3</c-col>
</c-row>
</c-container>
:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Setting one column width
Auto-layout for flexbox grid columns also means you can set the width of one column and have the sibling columns automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths. Note that the other columns will resize no matter the width of the center column.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-setting-one-column-width',
templateUrl: './grid-setting-one-column-width.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridSettingOneColumnWidthComponent {}<c-container>
<c-row>
<c-col>1 of 3</c-col>
<c-col xs="6">2 of 3 (wider)</c-col>
<c-col>3 of 3</c-col>
</c-row>
<c-row>
<c-col>1 of 3</c-col>
<c-col xs="6">2 of 3 (wider)</c-col>
<c-col>3 of 3</c-col>
</c-row>
</c-container>
:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Variable width content
Use c-col xs|sm|md|lg|xl="auto" props to size columns based on the natural width of their content.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-variable-width-content',
templateUrl: './grid-variable-width-content.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridVariableWidthContentComponent {}<c-container>
<c-row class="justify-content-md-center">
<c-col xs lg="2">1 of 3</c-col>
<c-col md="auto">Variable width content</c-col>
<c-col xs [lg]="2">3 of 3</c-col>
</c-row>
<c-row>
<c-col>1 of 3</c-col>
<c-col md="auto">Variable width content</c-col>
<c-col xs [lg]="2">3 of 3</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Responsive classes
CoreUI’s grid includes six tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, large, or extra large devices however you see fit.
All breakpoints
For grids that are the same from the smallest of devices to the largest, use the c-col and c-col xs= classes.
Specify a numbered class when you need a particularly sized column; otherwise, feel free to stick to c-col.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-all-breakpoints',
templateUrl: './grid-all-breakpoints.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridAllBreakpointsComponent {}<c-container>
<c-row>
<c-col>.col</c-col>
<c-col>.col</c-col>
<c-col>.col</c-col>
<c-col>.col</c-col>
</c-row>
<c-row>
<c-col xs="8">.col-8</c-col>
<c-col xs="4">.col-4</c-col>
</c-row>
</c-container>
:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Stacked to horizontal
Using a single set of c-col sm= classes, you can create a basic grid system that starts out stacked and becomes horizontal at the small breakpoint (sm).
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-stacked-horizontal',
templateUrl: './grid-stacked-horizontal.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridStackedHorizontalComponent {}<c-container>
<c-row>
<c-col sm="8">.col-sm-8</c-col>
<c-col sm="4">.col-sm-4</c-col>
</c-row>
<c-row>
<c-col sm>.col-sm</c-col>
<c-col sm>.col-sm</c-col>
<c-col sm>.col-sm</c-col>
</c-row>
</c-container>
:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Mix and match
Don’t want your columns to simply stack in some grid tiers? Use a combination of different classes for each tier as needed. See the example below for a better idea of how it all works.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-mix-match',
templateUrl: './grid-mix-match.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridMixMatchComponent {}<c-container>
<c-row>
<c-col md="8">.col-md-8</c-col>
<c-col xs="6" md="4">.col-6 .col-md-4</c-col>
</c-row>
<c-row>
<c-col xs="6" md="4">.col-6 .col-md-4</c-col>
<c-col xs="6" md="4">.col-6 .col-md-4</c-col>
<c-col xs="6" md="4">.col-6 .col-md-4</c-col>
</c-row>
<c-row>
<c-col xs="6">.col-6</c-col>
<c-col xs="6">.col-6</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Row columns
Use the responsive c-row [sm | md | lg | xl | xxl]=* classes to quickly set the number of columns that best render your
content and layout. Whereas normal c-col xs= classes apply to the individual columns (e.g., c-col xs="4"), the row
columns classes are set on the parent c-row as a shortcut. With c-row c-row [sm | md | lg | xl | xxl]="'auto'" you can
give the columns their natural width.
Use these row columns classes to quickly create basic grid layouts or to control your card layouts.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-row-columns',
templateUrl: './grid-row-columns.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridRowColumnsComponent {}<c-container>
<c-row [xs]="2">
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
</c-row>
</c-container>
:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-row-columns-2',
templateUrl: './grid-row-columns-2.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridRowColumns2Component {}<c-container>
<c-row [xs]="3">
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-row-columns-3',
templateUrl: './grid-row-columns-3.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridRowColumns3Component {}<c-container>
<c-row xs="auto">
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-row-columns-4',
templateUrl: './grid-row-columns-4.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridRowColumns4Component {}<c-container>
<c-row [xs]="4">
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-row-columns-5',
templateUrl: './grid-row-columns-5.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridRowColumns5Component {}<c-container>
<c-row [xs]="4">
<c-col>column</c-col>
<c-col>column</c-col>
<c-col xs="6">column</c-col>
<c-col>column</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-row-columns-6',
templateUrl: './grid-row-columns-6.component.html',
styleUrls: ['./grid.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class GridRowColumns6Component {}<c-container>
<c-row [xs]="1" [sm]="2" [md]="4">
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
<c-col>column</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Nesting
To nest your content with the default grid, add a new row and set of .col-sm-* columns within an existing .col-sm-* column.
Nested rows should include a set of columns that add up to 12 or fewer (it is not required that you use all 12 available columns).
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-grid-nesting',
imports: [ContainerComponent, RowComponent, ColComponent],
templateUrl: './grid-nesting.component.html',
styleUrls: ['./grid.component.scss']
})
export class GridNestingComponent {}<c-container class="text-center">
<c-row>
<c-col [sm]="3">
Level 1: .col-sm-3
</c-col>
<c-col [sm]="9">
<c-row>
<c-col [xs]="8" >
Level 2: .col-8
</c-col>
<c-col [xs]="4">
Level 2: .col-4
</c-col>
</c-row>
</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid var(--cui-border-color-translucent);
padding-bottom: .75rem;
padding-top: .75rem;
}
}API reference
Grid Module
import { GridModule } from '@coreui/angular';
@NgModule({
imports: [GridModule,]
})
export class AppModule() { }c-container
component
import { ContainerComponent } from '@coreui/angular'| Property | Default | Type |
|---|---|---|
| breakpoint | '' | string |
Set container 100% wide until a breakpoint. | ||
| fluid | false | boolean |
Set container 100% wide, spanning the entire width of the viewport. | ||
c-row cRow
component directive
import { RowComponent } from '@coreui/angular'gutter
directive for c-row
import { GutterDirective } from '@coreui/angular'| Property | Default | Type |
|---|---|---|
| gutter | {} | number, IGutterObject, GutterBreakpoints |
Define padding between columns to space and align content responsively in the Bootstrap grid system. | ||
c-col cCol
component directive
import { ColComponent } from '@coreui/angular'