Background

Convey meaning through background-color and add decoration with gradients.

Background color

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.

.bg-primary
.bg-secondary
.bg-success
.bg-danger
.bg-warning
.bg-info
.bg-light
.bg-dark
.bg-white
.bg-transparent
 <!-- background color -->
<div class="p-3 mb-2 bg-primary text-white">.bg-primary</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-white text-dark">.bg-white</div>
<div class="p-3 mb-2 bg-transparent text-dark">.bg-transparent</div>

Background Gradient color

By adding a .bg-light-gradient, .bg-light-gradient-top, .bg-light-gradient-bottom, .bg-gradient-mix-shade class, a linear gradient is added as background image to the backgrounds.

.bg-light-gradient
.bg-light-gradient-top
.bg-light-gradient-bottom
.bg-gradient-mix-shade
 <!-- background gradient -->
<div class="p-6 mb-3 bg-light-gradient text-dark rounded-3">.bg-light-gradient</div>
<div class="p-6 mb-3 bg-light-gradient-top text-dark rounded-3">.bg-light-gradient-top</div>
<div class="p-6 mb-3 bg-light-gradient-bottom text-dark rounded-3">.bg-light-gradient-bottom</div>
<div class="p-6 mb-3 bg-gradient-mix-shade text-white rounded-3">.bg-gradient-mix-shade</div>

Opacity

As of v5.1.0, background-color utilities are generated with Sass using CSS variables. This allows for real-time color changes without compilation and dynamic alpha transparency changes.

This is default success background
This is 75% opacity success background
This is 50% opacity success background
This is 25% opacity success background
This is 10% opacity success background
<!-- opacity -->
 <div class="bg-success p-2 text-white">This is default success background</div>
 <div class="bg-success p-2 text-white bg-opacity-75">This is 75% opacity success background</div>
 <div class="bg-success p-2 text-dark bg-opacity-50">This is 50% opacity success background</div>
 <div class="bg-success p-2 text-dark bg-opacity-25">This is 25% opacity success background</div>
 <div class="bg-success p-2 text-dark bg-opacity-10">This is 10% opacity success background</div>