Skip to content

Theme

Responsiveness

Learn how to adapt the layout to different screen sizes.

Breakpoints

You can add some properties that are only applied if a screen width is more than a certain size (aka breakpoint).

BreakpointMin Screen Width
Small (sm)520px
Medium (md)680px
Large (lg)880px
Extra Large (xl)1180px

The following properties can be responsive:

  • margins
  • paddings
  • text alignment
  • alignment and ordering of items in flex containers
  • flex layout (row/column)
  • visibility of elements

Live example: the current breakpoint of this window (built with .hidden-* classes)

Extra small (xs) — narrower than 520px Small (sm) — 520px to 679px Medium (md) — 680px to 879px Large (lg) — 880px to 1179px Extra large (xl) — 1180px and wider

Visibility

You can hide elements on certain breakpoints.

CSS ClassResult
.hiddenHides elements on all screen sizes.
.hidden-xs-upSame as .hidden. Hides elements on all screen sizes.
.hidden-sm-upHides elements on screens with a width of 520px or more.
.hidden-md-upHides elements on screens with a width of 680px or more.
.hidden-lg-upHides elements on screens with a width of 880px or more.
.hidden-xl-upHides elements on screens with a width of 1180px or more.
.hidden-xs-downHides elements on screens with a width of 519px or less.
.hidden-sm-downHides elements on screens with a width of 679px or less.
.hidden-md-downHides elements on screens with a width of 879px or less.
.hidden-lg-downHides elements on screens with a width of 1179px or less.
.hidden-xl-downSame as .hidden. Hides elements on all screen sizes.

Live example: resize the window to see the items appear and disappear

.hidden-sm-up .hidden-md-up .hidden-lg-up .hidden-xl-up .hidden-xs-down .hidden-sm-down .hidden-md-down .hidden-lg-down

Text Alignment

Text elements can have different alignments depending on a screen size.

Example #1: h1.text-center.text-sm-left.text-md-right.text-lg-center.text-xl-left

  • On screens up to 519px the text will be center-aligned
  • On screens 520px-679px the text will be left-aligned
  • On screens 680px-879px the text will be right-aligned
  • On screens 880px-1179px the text will be center-aligned
  • On screens 1180px and larger the text will be left-aligned

Live example #1

Responsive heading

Example #2: h1.text-md-center

  • On screens up to 679px the text will be left-aligned (by default)
  • On screens 680px and larger the text will be center-aligned

Live example #2

Responsive heading

CSS ClassResult
.text-sm-{alignment}Applied on screens with a width of 520px and larger
.text-md-{alignment}Applied on screens with a width of 680px and larger
.text-lg-{alignment}Applied on screens with a width of 880px and larger
.text-xl-{alignment}Applied on screens with a width of 1180px and larger

Note, that classes with a larger breakpoint have a higher specificity. This means that if you have two classes (e.g. .text-sm-center and .text-lg-left) the latter will be applied on screens 880px and larger.

Margins & Paddings

In the following example the horizontal margins on a text element gradually increase from 0px to 40px as the screen size increases.

Example: h1.mx-sm-8.mx-md-16.mx-lg-24.mx-xl-40

  • On screens up to 519px the horizontal margins will be 0px
  • On screens 520px-679px the horizontal margins will be 8px
  • On screens 680px-879px the horizontal margins will be 16px
  • On screens 880px-1179px the horizontal margins will be 24px
  • On screens 1180px and larger the horizontal margins will be 40px

The same rules can be applied to paddings.

Live example

Item 1

Flex Layout

In the following example the flex layout changes from column to row.

Example #1: .d-flex.flex-column.flex-md-row

  • On screens up to 679px the column layout is applied
  • On screens 680px and larger the row layout is applied

Live example #1

Item 1
Item 2
Item 3

In the following example the items are spread equally on small screens, and justified to the left side on larger screens.

Example #2: .d-flex.justify-content-around.justify-content-sm-start

  • On screens up to 519px the items are spread equally
  • On screens 520px and larger the items are justified to the left

Live example #2

Item 1
Item 2
Item 3