Introduction
MDB includes dozens of utilities—classes with a single purpose. They’re designed to reduce the frequency of highly repetitive declarations in your CSS while allowing for quick and easy development.
Responsive utilities
For faster mobile-friendly development, use these utility classes for showing and hiding content by device via media query. Also included are utility classes for toggling content when printed.
Try to use these on a limited basis and avoid creating entirely different versions of the same site. Instead, use them to complement each device’s presentation.
- The
.hidden-*-up
classes hide the element when the viewport is at the given breakpoint or wider. For example,.hidden-md-up
hides an element on medium, large, and extra-large viewports. - The
.hidden-*-down
classes hide the element when the viewport is at the given breakpoint or smaller. For example,.hidden-md-down
hides an element on extra-small, small, and medium viewports). - There are no explicit “visible”/”show” responsive utility classes; you make an element visible by simply not hiding it at that breakpoint size.
- You can combine one
.hidden-*-up
class with one.hidden-*-down
class to show an element only on a given interval of screen sizes. For example,.hidden-sm-down.hidden-xl-up
shows the element only on medium and large viewports. Using multiple.hidden-*-up
classes or multiple.hidden-*-down
classes is redundant and pointless. - These classes don’t attempt to accommodate less common cases where an element’s visibility can’t be expressed as a single contiguous range of viewport breakpoint sizes; you will instead need to use custom CSS in such cases.
Extra small devices Portrait phones (<544px) | Small devices Landscape phones (≥544px - <768px) | Medium devices Tablets (≥768px - <992px) | Large devices Desktops (≥992px - <1200px) | Extra large devices Desktops (≥1200px) | |
---|---|---|---|---|---|
.hidden-xs-down |
Hidden | Visible | Visible | Visible | Visible |
.hidden-sm-down |
Hidden | Hidden | Visible | Visible | Visible |
.hidden-md-down |
Hidden | Hidden | Hidden | Visible | Visible |
.hidden-lg-down |
Hidden | Hidden | Hidden | Hidden | Visible |
.hidden-xl-down |
Hidden | Hidden | Hidden | Hidden | Hidden |
.hidden-xs-up |
Hidden | Hidden | Hidden | Hidden | Hidden |
.hidden-sm-up |
Visible | Hidden | Hidden | Hidden | Hidden |
.hidden-md-up |
Visible | Visible | Hidden | Hidden | Hidden |
.hidden-lg-up |
Visible | Visible | Visible | Hidden | Hidden |
.hidden-xl-up |
Visible | Visible | Visible | Visible | Hidden |
Spacing
Assign margin
or padding
to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties. All classes are multiples on
the global default value, 1rem
.
The classes are named using the format: {property}{sides}-{size}
Where property is one of: * m
- for classes that set margin
* p
- for classes that set padding
Where sides is one of: * t
- for classes that set margin-top
or padding-top
* b
- for classes that set margin-bottom
or padding-bottom
* l
- for
classes that set margin-left
or padding-left
* r
- for classes that set margin-right
or padding-right
* x
- for classes that set both *-left
and *-right
* y
- for classes that set both *-top
and *-bottom
* a
- for classes that set a margin
or padding
on all 4 sides of the element
Where size is one of: * 0
- for classes that eliminate the margin
or padding
by setting it to 0
* 1
- (by default) for classes that set the margin
or padding
to $spacer-x
or $spacer-y
* 2
- (by default) for classes that set the margin
or padding
to $spacer-x * 1.5
or $spacer-y * 1.5
* 3
- (by
default) for classes that set the margin
or padding
to $spacer-x * 3
or $spacer-y * 3
Here are some representative examples of these classes:
.mt-0 {
margin-top: 0 !important;
}
.ml-1 {
margin-left: $spacer-x !important;
}
.px-2 {
padding-left: ($spacer-x * 1.5) !important;
padding-right: ($spacer-x * 1.5) !important;
}
.pa-3 {
padding: ($spacer-y * 3) ($spacer-x * 3) !important;
}
Additionally, Bootstrap also includes an .mx-auto
class which sets the horizontal margins to auto
.
Text alignment
Easily realign text to components with text alignment classes.
Justified text
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae magni ratione autem velit quod aliquid odit, ipsam praesentium cum. Itaque laudantium inventore sapiente consequatur blanditiis tenetur eos libero quaerat repellat.
<p class="text-justify">Justified text.</p>
For left, right, and center alignment, responsive classes are available that use the same viewport width breakpoints as the grid system.
Left aligned text on all viewport sizes.
Center aligned text on all viewport sizes.
Right aligned text on all viewport sizes.
Left aligned text on viewports sized SM (small) or wider.
Left aligned text on viewports sized MD (medium) or wider.
Left aligned text on viewports sized LG (large) or wider.
Left aligned text on viewports sized XL (extra-large) or wider.
<p class="text-xs-left">Left aligned text on all viewport sizes.</p>
<p class="text-xs-center">Center aligned text on all viewport sizes.</p>
<p class="text-xs-right">Right aligned text on all viewport sizes.</p>
<p class="text-sm-left">Left aligned text on viewports sized SM (small) or wider.</p>
<p class="text-md-left">Left aligned text on viewports sized MD (medium) or wider.</p>
<p class="text-lg-left">Left aligned text on viewports sized LG (large) or wider.</p>
<p class="text-xl-left">Left aligned text on viewports sized XL (extra-large) or wider.</p>
Text transform
Transform text in components with text capitalization classes.
Lowercased text.
Uppercased text.
CapiTaliZed text.
<p class="text-lowercase">Lowercased text.</p>
<p class="text-uppercase">Uppercased text.</p>
<p class="text-capitalize">CapiTaliZed text.</p>
Font weight and italics
Quickly change the weight (boldness) of text or italicize text.
Bold text.
Normal weight text.
Italicized text.
<p class="font-weight-bold">Bold text.</p>
<p class="font-weight-normal">Normal weight text.</p>
<p class="font-italic">Italicized text.</p>
Contextual colors and backgrounds
Convey meaning through color with a handful of emphasis utility classes. These may also be applied to links and will darken on hover just like our default link styles.
Fusce dapibus, tellus ac cursus commodo, tortor mauris nibh.
Nullam id dolor id nibh ultricies vehicula ut id elit.
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
Maecenas sed diam eget risus varius blandit sit amet non magna.
Etiam porta sem malesuada magna mollis euismod.
Donec ullamcorper nulla non metus auctor fringilla.
<p class="text-muted">Fusce dapibus, tellus ac cursus commodo, tortor mauris nibh.</p>
<p class="text-primary">Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p class="text-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p>
<p class="text-info">Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
<p class="text-warning">Etiam porta sem malesuada magna mollis euismod.</p>
<p class="text-danger">Donec ullamcorper nulla non metus auctor fringilla.</p>
Contextual text classes also work well on anchors with the provided hover and focus states.
Muted link Primary link Success link Info link Warning link Danger link
<a href="#" class="text-muted">Muted link</a>
<a href="#" class="text-primary">Primary link</a>
<a href="#" class="text-success">Success link</a>
<a href="#" class="text-info">Info link</a>
<a href="#" class="text-warning">Warning link</a>
<a href="#" class="text-danger">Danger link</a>
Similar to the contextual text color classes, easily set the background of an element to any contextual class. Anchor components will darken on hover, just like the text classes. Background utilities do not set color
, so in some cases you’ll want to use .text-*
utilities.
<div class="bg-primary text-white">Nullam id dolor id nibh ultricies vehicula ut id elit.</div>
<div class="bg-success text-white">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</div>
<div class="bg-info text-white">Maecenas sed diam eget risus varius blandit sit amet non magna.</div>
<div class="bg-warning text-white">Etiam porta sem malesuada magna mollis euismod.</div>
<div class="bg-danger text-white">Donec ullamcorper nulla non metus auctor fringilla.</div>
<div class="bg-inverse text-white">Cras mattis consectetur purus sit amet fermentum.</div>
Close icon
Use a generic close icon for dismissing content like modals and alerts. Be sure to include text for screen readers, as we’ve done with aria-label
.
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
Responsive floats
These utility classes float an element to the left or right, or disable floating, based on the current viewport size using the CSS float
property. !important
is included to avoid specificity issues. These use the same viewport width breakpoints as the grid system.
<div class="float-xs-left">Float left on all viewport sizes</div>
<div class="float-xs-right">Float right on all viewport sizes</div>
<div class="float-xs-none">Don't float on all viewport sizes</div>
<div class="float-sm-left">Float left on viewports sized SM (small) or wider</div>
<div class="float-md-left">Float left on viewports sized MD (medium) or wider</div>
<div class="float-lg-left">Float left on viewports sized LG (large) or wider</div>
<div class="float-xl-left">Float left on viewports sized XL (extra-large) or wider</div>
Center content
In order to center content vertically and horizontally, add class .flex-center
to the parent element.
Note: You have to define the height
of the parent element. You can use either relative units (like %, em or rem) or absolute (like px).
.example-parent {
height: 300px;
}
<div class="example-parent flex-center">
<div>Centered content</div>
</div>
Vertical alignment
Change the alignment of elements with the vertical-alignment
utilities. Please note that vertical-align only affects inline, inline-block, inline-table, and table cell elements.
Choose from .align-baseline
, .align-top
, .align-middle
, .align-bottom
, .align-text-bottom
, and .align-text-top
as needed.
With inline elements:
<span class="align-baseline">baseline</span>
<span class="align-top">top</span>
<span class="align-middle">middle</span>
<span class="align-bottom">bottom</span>
<span class="align-text-top">text-top</span>
<span class="align-text-bottom">text-bottom</span>
With table cells:
baseline | top | middle | bottom | text-top | text-bottom |
<table style="height: 100px;">
<tbody>
<tr>
<td class="align-baseline">baseline</td>
<td class="align-top">top</td>
<td class="align-middle">middle</td>
<td class="align-bottom">bottom</td>
<td class="align-text-top">text-top</td>
<td class="align-text-bottom">text-bottom</td>
</tr>
</tbody>
</table>