Learn how to modify columns with a handful of options for alignment, ordering, and offsetting thanks to flexbox grid system.
How they work
-
Columns build on the grid’s flexbox architecture. Flexbox means we have options for changing individual columns and modifying groups of columns at the row level. You choose how columns grow, shrink, or otherwise change.
-
When building grid layouts, all content goes in columns. The hierarchy of CoreUI grid goes from container to row to column to your content. On rare occasions, you may combine content and column, but be aware there can be unintended consequences.
-
CoreUI for Angular includes predefined components for creating fast, responsive layouts. With six breakpoints and a dozen columns at each grid tier, we have dozens of components already built for you to create your desired layouts. This can be disabled via Sass if you wish.
Alignment
Use flexbox alignment utilities to vertically and horizontally align columns.
Vertical alignment
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-vertical-alignment',
templateUrl: './columns-vertical-alignment.component.html',
styleUrls: ['./columns-vertical-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsVerticalAlignmentComponent {}<c-container>
<c-row class="align-items-start">
<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-row class="align-items-center">
<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-row class="align-items-end">
<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 {
background-color: rgba(255, 0, 0, .1);
min-height: 10rem;
}
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-vertical-alignment-2',
templateUrl: './columns-vertical-alignment-2.component.html',
styleUrls: ['./columns-vertical-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsVerticalAlignment2Component {}<c-container>
<c-row>
<c-col class="align-self-start">One of three columns</c-col>
<c-col class="align-self-center">One of three columns</c-col>
<c-col class="align-self-end">One of three columns</c-col>
</c-row>
</c-container>
:host {
.row {
background-color: rgba(255, 0, 0, .1);
min-height: 10rem;
}
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Horizontal alignment
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-horizontal-alignment',
templateUrl: './columns-horizontal-alignment.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsHorizontalAlignmentComponent {}<c-container>
<c-row class="justify-content-start">
<c-col xs="4">
One of two columns
</c-col>
<c-col xs="4">
One of two columns
</c-col>
</c-row>
<c-row class="justify-content-center">
<c-col xs="4">
One of two columns
</c-col>
<c-col xs="4">
One of two columns
</c-col>
</c-row>
<c-row class="justify-content-end">
<c-col xs="4">
One of two columns
</c-col>
<c-col xs="4">
One of two columns
</c-col>
</c-row>
<c-row class="justify-content-around">
<c-col xs="4">
One of two columns
</c-col>
<c-col xs="4">
One of two columns
</c-col>
</c-row>
<c-row class="justify-content-between">
<c-col xs="4">
One of two columns
</c-col>
<c-col xs="4">
One of two columns
</c-col>
</c-row>
<c-row class="justify-content-evenly">
<c-col xs="4">
One of two columns
</c-col>
<c-col xs="4">
One of two 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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Column wrapping
If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-wrapping',
templateUrl: './columns-wrapping.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsWrappingComponent {}<c-container>
<c-row>
<c-col xs="9">.col-9</c-col>
<c-col xs="4">
.col-4
<br />
Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one
contiguous unit.
</c-col>
<c-col xs="6">
.col-6
<br />
Subsequent columns continue along the new line.
</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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Column breaks
Breaking columns to a new line in flexbox requires a small hack - add an element with width: 100% wherever you want
to wrap your columns to a new line. Normally this is accomplished with multiple c-rows, but not every implementation
method can account for this.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-breaks',
templateUrl: './columns-breaks.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsBreaksComponent {}<c-container>
<c-row>
<c-col xs="6" sm="3">.col-6 .col-sm-3</c-col>
<c-col xs="6" sm="3">.col-6 .col-sm-3</c-col>
<div class="w-100"></div>
<c-col xs="6" sm="3">.col-6 .col-sm-3</c-col>
<c-col xs="6" sm="3">.col-6 .col-sm-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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}You may also apply this break at specific breakpoints with our responsive display utilities.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-breaks-2',
templateUrl: './columns-breaks-2.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsBreaks2Component {}<c-container>
<c-row>
<c-col xs="6" sm="4">
.col-6 .col-sm-4
</c-col>
<c-col xs="6" sm="4">
.col-6 .col-sm-4
</c-col>
<div class="w-100 d-none d-md-block"></div>
<c-col xs="6" sm="4">
.col-6 .col-sm-4
</c-col>
<c-col xs="6" sm="4">
.col-6 .col-sm-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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Reordering
Order props
Use order="1" (first, 1..5, last) props for controlling the visual order of your content. These props are
responsive, so you can set the order by breakpoint (e.g., order="{xs: 1, md: 2}").
Includes support for 1 through 5 across all six grid tiers.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-order-props',
templateUrl: './columns-order-props.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsOrderPropsComponent {}<c-container>
<c-row>
<c-col>
First in DOM, no order applied
</c-col>
<c-col [order]="5">
Second in DOM, with a larger order
</c-col>
<c-col [order]="{xs: 1}">
Third in DOM, with an order of 1
</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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}There are also responsive props order="first" and order="last" with responsive variations
order={xs: "last", sm: "first"} that change the order of an element by applying order: -1 and order: 6,
respectively. These values can also be intermixed with the numbered 1..5 values as needed.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-order-props-2',
templateUrl: './columns-order-props-2.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsOrderProps2Component {}<c-container>
<c-row>
<c-col order="last">
First in DOM, ordered last
</c-col>
<c-col>
Second in DOM, unordered
</c-col>
<c-col [order]="{ xs: 'first' }">
Third in DOM, ordered first
</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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Offsetting columns
You can offset grid columns in two ways: our col props offset="0..12" with responsive variations
offset={md: 2, lg: 3} col props and our margin utilities.
Grid props are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.
Offset prop
Move columns to the right using offset={ md: * } props. These props increase the left margin of a column by * columns.
For example, offset={ md: 4 } moves .col-md-4 over four columns.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-offset-prop',
templateUrl: './columns-offset-prop.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsOffsetPropComponent {}<c-container>
<c-row>
<c-col md="4">.col-md-4</c-col>
<c-col md="4" [offset]="{md: 4}" >.col-md-4 .offset-md-4</c-col>
</c-row>
<c-row>
<c-col md="3" [offset]="{md: 3}" >.col-md-3 .offset-md-3</c-col>
<c-col md="3" [offset]="{md: 3}">.col-md-3 .offset-md-3</c-col>
</c-row>
<c-row>
<c-col md="6" [offset]="{md: 3}">.col-md-6 .offset-md-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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-offset-prop-2',
templateUrl: './columns-offset-prop-2.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsOffsetProp2Component {}<c-container>
<c-row>
<c-col sm="5" md="6">
.col-sm-5 .col-md-6
</c-col>
<c-col sm="5" md="6" [offset]="{sm: 2, md: 0}">
.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0
</c-col>
</c-row>
<c-row>
<c-col sm="6" md="5" lg="6">
.col-sm-6 .col-md-5 .col-lg-6
</c-col>
<c-col sm="6" md="5" lg="6" [offset]="{md: 2, lg: 0}">
.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0
</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 rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Margin utilities
You can use margin utilities like .me-auto to force sibling columns away from one another.
import { Component } from '@angular/core';
import { ColComponent, ContainerComponent, RowComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-margin-utilities',
templateUrl: './columns-margin-utilities.component.html',
styleUrls: ['./columns-margin-utilities.component.scss'],
imports: [ContainerComponent, RowComponent, ColComponent]
})
export class ColumnsMarginUtilitiesComponent {}<c-container>
<c-row>
<c-col md="4">.col-md-4</c-col>
<c-col md="4" class="ms-auto">.col-md-4 .ms-auto</c-col>
</c-row>
<c-row>
<c-col md="3" class="ms-md-auto">.col-md-3 .ms-md-auto</c-col>
<c-col md="3" class="ms-md-auto">.col-md-3 .ms-md-auto</c-col>
</c-row>
<c-row>
<c-col xs="auto" class="me-auto">.col-auto .me-auto</c-col>
<c-col xs="auto">.col-auto</c-col>
</c-row>
</c-container>:host {
.row+.row {
margin-top: 1rem;
}
c-col {
background-color: rgba(39, 41, 43, .03);
border: 1px solid rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}Standalone columns
The c-col component can also be used outside a c-row to give an element a specific width. Whenever column
component are used as non direct children of a row, the paddings are omitted.
import { Component } from '@angular/core';
import { ColComponent } from '@coreui/angular';
@Component({
selector: 'docs-columns-standalone',
templateUrl: './columns-standalone.component.html',
styleUrls: ['./columns-horizontal-alignment.component.scss'],
imports: [ColComponent]
})
export class ColumnsStandaloneComponent {}<c-col xs="3" class="bg-light p-3 border">
.col-3: width of 25%
</c-col>
<c-col sm="9" class="bg-light p-3 border">
.col-sm-9: width of 75% above sm breakpoint
</c-col>:host {
.row+.row {
margin-top: 1rem;
}
.row > .col, .row > [class^=col-] {
background-color: rgba(39, 41, 43, .03);
border: 1px solid rgba(39, 41, 43, .1);
padding-bottom: .75rem;
padding-top: .75rem;
}
}The classes can be used together with utilities to create responsive floated images. Make sure to wrap the content in
a .clearfix wrapper to clear the float if the text is shorter.
import { Component } from '@angular/core';
import { ColDirective } from '@coreui/angular';
@Component({
selector: 'docs-columns-standalone-2',
templateUrl: './columns-standalone-2.component.html',
imports: [ColDirective]
})
export class ColumnsStandalone2Component {}<div class="clearfix">
<img cCol md="6" class="float-md-end mb-3 ms-md-3" src="/assets/img/angular.jpg" alt="CoreUI for Angular" style="max-width: 100%;" />
<p>
Notice the use of <code>cCol md="6"</code> directive. We're using it here to show the use of the
clearfix class. We're adding quite a few meaningless phrases here to
demonstrate how the columns interact here with the floated image.
</p>
<p>
As you can see the paragraphs gracefully wrap around the floated image. Now
imagine how this would look with some actual content in here, rather than
just this boring placeholder text that goes on and on, but actually conveys
no tangible information at. It simply takes up space and should not really
be read.
</p>
<p>
And yet, here you are, still persevering in reading this placeholder text,
hoping for some more insights, or some hidden easter egg of content. A joke,
perhaps. Unfortunately, there's none of that here.
</p>
</div>API reference
Grid Module
import { GridModule } from '@coreui/angular';
@NgModule({
imports: [GridModule,]
})
export class AppModule() { }c-col cCol
component directive
import { ColComponent } from '@coreui/angular'