Bootstrap Contextual Colors and Backgrounds

Bootstrap has contextual classes that is used to provide meaning through colors.

images/coding/coding02.webp

Contextual Classes

  1. primary
  2. secondary
  3. success
  4. danger
  5. warning
  6. info
  7. light
  8. dark

Text Colors

The classes for text colors are:

  1. .text-muted
  2. .text-primary
  3. .text-secondary
  4. .text-success
  5. .text-info
  6. .text-warning
  7. .text-danger
  8. .text-light
  9. .text-dark

Contextual text classes can also work on anchors (links).

Background Colors

Similar to the contextual text color classes, you can easily set the background color. Background utilities do not set color, so in some cases you may need to add text color utilities for contrasting text.

  1. .bg-primary
  2. .bg-secondary
  3. .bg-success
  4. .bg-info
  5. .bg-warning
  6. .bg-danger
  7. .bg-light
  8. .bg-dark
  9. .bg-white
  10. .bg-transparent
  11. .bg-body

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.

Background Opacity

You can add .bg-opacity utility classes:

  • bg-opacity-10
  • bg-opacity-25
  • bg-opacity-50
  • bg-opacity-25

Colors in Tables

Contextual classes can be used to color table rows (<tr> or <th>) or individual table cells (<td>).

  1. .active
  2. .primary
  3. .secondary
  4. .success
  5. .info
  6. .warning
  7. .danger
  8. .light
  9. .dark

Buttons

You can add button classes on <a>, <button>, or <input> elements. You need to add class .btn to make a link or element look like a button.

  1. .btn-default
  2. .btn-primary
  3. .btn-secondary
  4. .btn-success
  5. .btn-info
  6. .btn-warning
  7. .btn-danger
  8. .btn-light
  9. .btn-dark
  10. .btn-link

Outline Buttons

You can remove all background images and colors on any button by replacing the default modifier classes with the .btn-outline-*.

Sizes

You can add .btn-lg or .btn-sm for additional sizes. You can create block level buttons by adding .btn-block class.

Disabled Buttons

You can make buttons look inactive by adding the disabled boolean attribute to any <button> element.