Utilities
Background Color
Similar to the contextual text color classes, set the background of an element to any contextual class. Background
utilities do not set color
, so in some cases you’ll want to use .text-*
color utilities.
<div class="p-2 mb-2 bg-primary text-white">.bg-primary</div>
<div class="p-2 mb-2 bg-secondary text-white">.bg-secondary</div>
<div class="p-2 mb-2 bg-success text-white">.bg-success</div>
<div class="p-2 mb-2 bg-danger text-white">.bg-danger</div>
<div class="p-2 mb-2 bg-warning text-dark">.bg-warning</div>
<div class="p-2 mb-2 bg-info text-dark">.bg-info</div>
<div class="p-2 mb-2 bg-light text-dark">.bg-light</div>
<div class="p-2 mb-2 bg-dark text-white">.bg-dark</div>
<div class="p-2 mb-2 bg-body text-dark">.bg-body</div>
<div class="p-2 mb-2 bg-white text-dark">.bg-white</div>
<div class="p-2 bg-transparent text-dark">.bg-transparent</div>
Background Gradient Color
By adding a .bg-gradient
class, a linear gradient is added as background image to the backgrounds. This
gradient starts with a semi-transparent white which fades out to the bottom.
<div class="p-2 mb-2 bg-primary bg-gradient text-white">.bg-primary.bg-gradient</div>
<div class="p-2 mb-2 bg-secondary bg-gradient text-white">.bg-secondary.bg-gradient</div>
<div class="p-2 mb-2 bg-success bg-gradient text-white">.bg-success.bg-gradient</div>
<div class="p-2 mb-2 bg-danger bg-gradient text-white">.bg-danger.bg-gradient</div>
<div class="p-2 mb-2 bg-warning bg-gradient text-dark">.bg-warning.bg-gradient</div>
<div class="p-2 mb-2 bg-info bg-gradient text-dark">.bg-info.bg-gradient</div>
<div class="p-2 mb-2 bg-light bg-gradient text-dark">.bg-light.bg-gradient</div>
<div class="p-2 mb-2 bg-dark bg-gradient text-white">.bg-dark.bg-gradient</div>
Background Opacity
background-color
utilities are generated with Sass using CSS variables. This
allows for real-time color changes without compilation and dynamic alpha transparency changes.
<div class="bg-primary p-2 text-white">This is default primary background</div>
<div class="bg-primary p-2 text-white bg-opacity-75">This is 75% opacity primary background</div>
<div class="bg-primary p-2 text-dark bg-opacity-50">This is 50% opacity primary background</div>
<div class="bg-primary p-2 text-dark bg-opacity-25">This is 25% opacity primary background</div>
<div class="bg-primary p-2 text-dark bg-opacity-10">This is 10% opacity success background</div>
Text Color
Colorize text with color utilities. If you want to colorize links, you can use the .link-*
helper classes which have :hover
and :focus
states.
.text-primary
.text-secondary
.text-success
.text-danger
.text-warning
.text-info
.text-light
.text-dark
.text-body
.text-muted
.text-white
.text-black-50
.text-white-50
<p class="text-primary">.text-primary</p>
<p class="text-secondary">.text-secondary</p>
<p class="text-success">.text-success</p>
<p class="text-danger">.text-danger</p>
<p class="text-warning bg-dark">.text-warning</p>
<p class="text-info bg-dark">.text-info</p>
<p class="text-light bg-dark">.text-light</p>
<p class="text-dark">.text-dark</p>
<p class="text-body">.text-body</p>
<p class="text-muted">.text-muted</p>
<p class="text-white bg-dark">.text-white</p>
<p class="text-black-50">.text-black-50</p>
<p class="text-white-50 bg-dark">.text-white-50</p>
Text Opacity Color
text color utilities are generated with Sass using CSS variables. This allows for real-time color changes without compilation and dynamic alpha transparency changes.
<div class="text-primary">This is default primary text</div>
<div class="text-primary text-opacity-75">This is 75% opacity primary text</div>
<div class="text-primary text-opacity-50">This is 50% opacity primary text</div>
<div class="text-primary text-opacity-25">This is 25% opacity primary text</div>
Opacity
The opacity
property sets the opacity level for an element. The opacity level describes the transparency
level, where 1
is not transparent at all, .5
is 50% visible, and 0
is
completely transparent. Set the opacity
of an element using .opacity-{value}
utilities.
<div class="opacity-100 p-2 bg-primary text-light fw-bold rounded">100%</div>
<div class="opacity-75 p-2 bg-primary text-light fw-bold rounded">75%</div>
<div class="opacity-50 p-2 bg-primary text-light fw-bold rounded">50%</div>
<div class="opacity-25 p-2 bg-primary text-light fw-bold rounded">25%</div>
Additive(Add) Border
Use border utilities to add an element’s borders. Choose from all borders or one at a time.
<span class="border"></span>
<span class="border-top"></span>
<span class="border-end"></span>
<span class="border-bottom"></span>
<span class="border-start"></span>
Subtractive(Remove) Border
Use border utilities to remove an element’s borders. Choose from all borders or one at a time.
<span class="border border-0"></span>
<span class="border border-top-0"></span>
<span class="border border-end-0"></span>
<span class="border border-bottom-0"></span>
<span class="border border-start-0"></span>
Border Color
Change the border color using utilities built on our theme colors.
<span class="border border-primary"></span>
<span class="border border-secondary"></span>
<span class="border border-success"></span>
<span class="border border-danger"></span>
<span class="border border-warning"></span>
<span class="border border-info"></span>
<span class="border border-light"></span>
<span class="border border-dark"></span>
Border Width Size
<span class="border border-1"></span>
<span class="border border-2"></span>
<span class="border border-3"></span>
<span class="border border-4"></span>
<span class="border border-5"></span>
Border Opacity
choose from any of the .border-opacity
utilities:
<div class="bg-primary p-2 text-white">This is default primary background</div>
<div class="bg-primary p-2 text-white bg-opacity-75">This is 75% opacity primary background</div>
<div class="bg-primary p-2 text-dark bg-opacity-50">This is 50% opacity primary background</div>
<div class="bg-primary p-2 text-dark bg-opacity-25">This is 25% opacity primary background</div>
<div class="bg-primary p-2 text-dark bg-opacity-10">This is 10% opacity success background</div>
Border Radius
Add classes to an element to easily round its corners.
<img src="..." class="rounded" alt="...">
<img src="..." class="rounded-top" alt="...">
<img src="..." class="rounded-end" alt="...">
<img src="..." class="rounded-bottom" alt="...">
<img src="..." class="rounded-start" alt="...">
<img src="..." class="rounded-circle" alt="...">
<img src="..." class="rounded-pill" alt="...">
Border Radius Size
Use the scaling classes for larger or smaller rounded corners. Sizes range from 0
to 5
.
<img src="..." class="rounded-0" alt="...">
<img src="..." class="rounded-1" alt="...">
<img src="..." class="rounded-2" alt="...">
<img src="..." class="rounded-3" alt="...">
<img src="..." class="rounded-4" alt="...">
<img src="..." class="rounded-5" alt="...">
Text Selection
Use user-select-all
, user-select-auto
, or
user-select-none
class to the content which is selected when the user interacts with it.
This paragraph will be entirely selected when clicked by the user.
This paragraph has default select behavior.
This paragraph will not be selectable when clicked by the user.
<p class="user-select-all">This paragraph will be entirely selected when clicked by the user.</p>
<p class="user-select-auto">This paragraph has default select behavior.</p>
<p class="user-select-none">This paragraph will not be selectable when clicked by the user.</p>
Pointer Events
Bootstrap provides .pe-none
and .pe-auto
classes to prevent or add element interactions.
This link can not be clicked.
This link can be clicked (this is default behavior).
This link can not be clicked because the
pointer-events
property is inherited from its parent. However, this
link has a pe-auto
class and can be clicked.
<p><a href="#" class="pe-none" tabindex="-1" aria-disabled="true">This link</a> can not be clicked.</p>
<p><a href="#" class="pe-auto">This link</a> can be clicked (this is default behavior).</p>
<p class="pe-none"><a href="#" tabindex="-1" aria-disabled="true">This link</a> can not be clicked because the
<code>pointer-events</code> property is inherited from its parent. However, <a href="#" class="pe-auto">this
link</a> has a <code>pe-auto</code> class and can be clicked.</p>
Overflow
Adjust the overflow
property on the fly with four default values and classes. These classes are not
responsive by default.
.overflow-auto
on an element with set width and height dimensions. By
design, this content will vertically scroll.
.overflow-hidden
on an element with set width and height dimensions.
.overflow-visible
on an element with set width and height dimensions.
.overflow-scroll
on an element with set width and height dimensions.
<div class="overflow-auto">...</div>
<div class="overflow-hidden">...</div>
<div class="overflow-visible">...</div>
<div class="overflow-scroll">...</div>
Position in Arrange
Arrange elements easily with the edge positioning utilities. The format is {property}-{position}
.
<div class="position-relative">
<div class="position-absolute top-0 start-0"></div>
<div class="position-absolute top-0 end-0"></div>
<div class="position-absolute top-50 start-50"></div>
<div class="position-absolute bottom-50 end-50"></div>
<div class="position-absolute bottom-0 start-0"></div>
<div class="position-absolute bottom-0 end-0"></div>
</div>
Position in Center
In addition, you can also center the elements with the transform utility class .translate-middle
.
<div class="position-relative">
<div class="position-absolute top-0 start-0 translate-middle"></div>
<div class="position-absolute top-0 start-50 translate-middle"></div>
<div class="position-absolute top-0 start-100 translate-middle"></div>
<div class="position-absolute top-50 start-0 translate-middle"></div>
<div class="position-absolute top-50 start-50 translate-middle"></div>
<div class="position-absolute top-50 start-100 translate-middle"></div>
<div class="position-absolute top-100 start-0 translate-middle"></div>
<div class="position-absolute top-100 start-50 translate-middle"></div>
<div class="position-absolute top-100 start-100 translate-middle"></div>
</div>
Position in Axis
By adding .translate-middle-x
or .translate-middle-y
classes, elements can be positioned only in horizontal or vertical direction.
<div class="position-relative">
<div class="position-absolute top-0 start-0"></div>
<div class="position-absolute top-0 start-50 translate-middle-x"></div>
<div class="position-absolute top-0 end-0"></div>
<div class="position-absolute top-50 start-0 translate-middle-y"></div>
<div class="position-absolute top-50 start-50 translate-middle"></div>
<div class="position-absolute top-50 end-0 translate-middle-y"></div>
<div class="position-absolute bottom-0 start-0"></div>
<div class="position-absolute bottom-0 start-50 translate-middle-x"></div>
<div class="position-absolute bottom-0 end-0"></div>
</div>
Shadows
While shadows on components are disabled by default in Bootstrap and can be enabled via
$enable-shadows
, you can also quickly add or remove a shadow with our box-shadow
utility
classes. Includes support for .shadow-none
and three default sizes (which have associated variables to
match).
<div class="shadow-none p-2 mb-2 bg-light rounded">No shadow</div>
<div class="shadow-sm p-2 mb-2 rounded">Small shadow</div>
<div class="shadow p-2 mb-2 rounded">Regular shadow</div>
<div class="shadow-lg p-2 mb-2 rounded">Larger shadow</div>
Width
Width utilities are generated from the utility API in _utilities.scss
. Includes support for
25%
, 50%
, 75%
, 100%
, and auto
by default. Modify
those values as you need to generate different utilities here.
<!-- Width -->
<div class="w-25 p-2 bg-light">Width 25%</div>
<div class="w-50 p-2 bg-light">Width 50%</div>
<div class="w-75 p-2 bg-light">Width 75%</div>
<div class="w-100 p-2 bg-light">Width 100%</div>
<div class="w-auto p-2 bg-light">Width auto</div>
Height
Height utilities are generated from the utility API in _utilities.scss
. Includes support for
25%
, 50%
, 75%
, 100%
, and auto
by default. Modify
those values as you need to generate different utilities here.
<!-- Height -->
<div class="h-25 p-2 bg-light">Height25%</div>
<div class="h-50 p-2 bg-light">Height50%</div>
<div class="h-75 p-2 bg-light">Height75%</div>
<div class="h-100 p-2 bg-light">Height100%</div>
<div class="h-auto p-2 bg-light">Height auto</div>