Backgrounds
Convey meaning through background-color
and add decoration with gradients.
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.
.bg-primary
.bg-primary-dark
.bg-secondary
.bg-success
.bg-danger
.bg-warning
.bg-info
.bg-light
.bg-dark
.bg-body
.bg-white
.bg-transparent
<div class="p-3 mb-2 bg-primary text-white">.bg-primary</div>
<div class="p-3 mb-2 bg-primary-dark text-white">.bg-primary-dark</div>
<div class="p-3 mb-2 bg-secondary text-white">.bg-secondary</div>
<div class="p-3 mb-2 bg-success text-white">.bg-success</div>
<div class="p-3 mb-2 bg-danger text-white">.bg-danger</div>
<div class="p-3 mb-2 bg-warning text-dark">.bg-warning</div>
<div class="p-3 mb-2 bg-info text-white">.bg-info</div>
<div class="p-3 mb-2 bg-light text-dark">.bg-light</div>
<div class="p-3 mb-2 bg-dark text-white">.bg-dark</div>
<div class="p-3 mb-2 bg-body text-dark">.bg-body</div>
<div class="p-3 mb-2 bg-white text-dark">.bg-white</div>
<div class="p-3 mb-2 bg-transparent text-dark">.bg-transparent</div>
Background soft color
.bg-soft-primary
.bg-soft-primary-light
.bg-soft-secondary
.bg-soft-success
.bg-soft-danger
.bg-soft-warning
.bg-soft-info
.bg-soft-light
.bg-soft-dark
.bg-soft-body
.bg-soft-white
<div class="p-3 mb-2 bg-soft-primary text-primary">.bg-soft-primary</div>
<div class="p-3 mb-2 bg-soft-primary-light text-primary">.bg-soft-primary-light</div>
<div class="p-3 mb-2 bg-soft-secondary text-secondary">.bg-soft-secondary</div>
<div class="p-3 mb-2 bg-soft-success text-success">.bg-soft-success</div>
<div class="p-3 mb-2 bg-soft-danger text-danger">.bg-soft-danger</div>
<div class="p-3 mb-2 bg-soft-warning text-warning">.bg-soft-warning</div>
<div class="p-3 mb-2 bg-soft-info text-info">.bg-soft-info</div>
<div class="p-3 mb-2 bg-soft-light text-light">.bg-soft-light</div>
<div class="p-3 mb-2 bg-soft-dark text-dark">.bg-soft-dark</div>
<div class="p-3 mb-2 bg-soft-body text-body">.bg-soft-body</div>
<div class="p-3 mb-2 bg-soft-white text-white">.bg-soft-white</div>
Background gradient
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.
Do you need a gradient in your custom CSS? Just add background-image: var(--bs-gradient);
.
.bg-primary.bg-gradient
.bg-primary-dark.bg-gradient
.bg-secondary.bg-gradient
.bg-success.bg-gradient
.bg-danger.bg-gradient
.bg-warning.bg-gradient
.bg-info.bg-gradient
.bg-light.bg-gradient
.bg-dark.bg-gradient
<div class="p-3 mb-2 bg-primary bg-gradient text-white">.bg-primary.bg-gradient</div>
<div class="p-3 mb-2 bg-primary-dark bg-gradient text-white">.bg-primary-dark.bg-gradient</div>
<div class="p-3 mb-2 bg-secondary bg-gradient text-white">.bg-secondary.bg-gradient</div>
<div class="p-3 mb-2 bg-success bg-gradient text-white">.bg-success.bg-gradient</div>
<div class="p-3 mb-2 bg-danger bg-gradient text-white">.bg-danger.bg-gradient</div>
<div class="p-3 mb-2 bg-warning bg-gradient text-dark">.bg-warning.bg-gradient</div>
<div class="p-3 mb-2 bg-info bg-gradient text-white">.bg-info.bg-gradient</div>
<div class="p-3 mb-2 bg-light bg-gradient text-dark">.bg-light.bg-gradient</div>
<div class="p-3 mb-2 bg-dark bg-gradient text-white">.bg-dark.bg-gradient</div>
Background image hero
Specify the position of a background image:
Use .bg-img-start
for top-aligned position.
<div class="bg-img-start" style="background-image: url(../assets/img/documentation/img7.jpg); height: 250px;"></div>
Use .bg-img-center
for center-aligned position.
<div class="bg-img-center" style="background-image: url(../assets/img/documentation/img7.jpg); height: 250px;"></div>
Use .bg-img-end
for bottom-aligned position.