Dealing with specificity

Sometimes contextual classes cannot be applied due to the specificity of another selector. In some cases, a sufficient workaround is to wrap your element’s content in a <div> with the class.

Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden class.

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.

Colors - 图1

  1. <p class="text-primary">.text-primary</p>
  2. <p class="text-secondary">.text-secondary</p>
  3. <p class="text-success">.text-success</p>
  4. <p class="text-danger">.text-danger</p>
  5. <p class="text-warning bg-dark">.text-warning</p>
  6. <p class="text-info bg-dark">.text-info</p>
  7. <p class="text-light bg-dark">.text-light</p>
  8. <p class="text-dark">.text-dark</p>
  9. <p class="text-body">.text-body</p>
  10. <p class="text-muted">.text-muted</p>
  11. <p class="text-white bg-dark">.text-white</p>
  12. <p class="text-black-50">.text-black-50</p>
  13. <p class="text-white-50 bg-dark">.text-white-50</p>

Background color

Similar to the contextual text color classes, easily 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-* utilities.

Colors - 图2

  1. <div class="p-3 mb-2 bg-primary text-white">.bg-primary</div>
  2. <div class="p-3 mb-2 bg-secondary text-white">.bg-secondary</div>
  3. <div class="p-3 mb-2 bg-success text-white">.bg-success</div>
  4. <div class="p-3 mb-2 bg-danger text-white">.bg-danger</div>
  5. <div class="p-3 mb-2 bg-warning text-dark">.bg-warning</div>
  6. <div class="p-3 mb-2 bg-info text-dark">.bg-info</div>
  7. <div class="p-3 mb-2 bg-light text-dark">.bg-light</div>
  8. <div class="p-3 mb-2 bg-dark text-white">.bg-dark</div>
  9. <div class="p-3 mb-2 bg-white text-dark">.bg-white</div>
  10. <div class="p-3 mb-2 bg-transparent text-dark">.bg-transparent</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-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