Background

Convey meaning through background-color.

Accessibility tip: Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies like screen readers. Please ensure the meaning is obvious from the content itself (e.g., the visible text with a sufficient color contrast) or is included through alternative means, such as additional text hidden with the .visually-hidden class.

Background color

Background utilities like .bg-* are generated from our original $theme-colors Sass map and respond to color modes.

Similar to the contextual text color classes, set the background of an element to any contextual class. Background utilities do not set color, so depending on the cases you’ll want to use:

.bg-primary
.bg-secondary
.bg-success
.bg-danger
.bg-warning
.bg-info
.bg-light
.bg-dark
.bg-body-secondary
.bg-body
.bg-black
.bg-white
.bg-transparent
html
<div class="p-3 mb-2 fw-bold bg-primary"><span class="text-bg-primary">.bg-primary</span></div>
<div class="p-3 mb-2 fw-bold bg-secondary"><span class="text-bg-secondary">.bg-secondary</span></div>
<div class="p-3 mb-2 fw-bold bg-success"><span class="text-bg-success">.bg-success</span></div>
<div class="p-3 mb-2 fw-bold bg-danger"><span class="text-bg-danger">.bg-danger</span></div>
<div class="p-3 mb-2 fw-bold bg-warning"><span class="text-bg-warning">.bg-warning</span></div>
<div class="p-3 mb-2 fw-bold bg-info"><span class="text-bg-info">.bg-info</span></div>
<div class="p-3 mb-2 fw-bold bg-light"><span class="text-bg-light">.bg-light</span></div>
<div class="p-3 mb-2 fw-bold bg-dark"><span class="text-bg-dark">.bg-dark</span></div>
<div class="p-3 mb-2 fw-bold bg-body-secondary">.bg-body-secondary</div>
<div class="p-3 mb-2 fw-bold bg-body">.bg-body</div>
<div class="p-3 mb-2 fw-bold bg-black text-white">.bg-black</div>
<div class="p-3 mb-2 fw-bold bg-white text-black">.bg-white</div>
<div class="p-3 mb-2 fw-bold bg-transparent">.bg-transparent</div>

Supporting background utilities are generated from our supporting colors. Please note that their color value stays the same between light and dark mode.

.bg-supporting-green
.bg-supporting-purple
.bg-supporting-yellow
.bg-supporting-blue
.bg-supporting-pink
.bg-supporting-orange
html
<div class="p-3 mb-2 fw-bold bg-supporting-green text-black">.bg-supporting-green</div>
<div class="p-3 mb-2 fw-bold bg-supporting-purple text-black">.bg-supporting-purple</div>
<div class="p-3 mb-2 fw-bold bg-supporting-yellow text-black">.bg-supporting-yellow</div>
<div class="p-3 mb-2 fw-bold bg-supporting-blue text-black">.bg-supporting-blue</div>
<div class="p-3 mb-2 fw-bold bg-supporting-pink text-black">.bg-supporting-pink</div>
<div class="p-3 mb-2 fw-bold bg-supporting-orange text-black">.bg-supporting-orange</div>
See list of Bootstrap-specific background color utilities

Another background utility is .bg-body-tertiary but doesn’t have any matching color in our grays colors so shouldn’t be used for now.

.bg-body-tertiary

html
<p class="p-3 mb-2 fw-bold bg-body-tertiary">.bg-body-tertiary</p>

In Bootstrap, for each .bg-* there is a matching .bg-*-subtle utility responding to color modes. In Boosted, subtle colors don’t exist so these background utilities have exactly the same value and shouldn’t be used. Prefer the regular .bg-* utilities instead.

.bg-primary-subtle
.bg-secondary-subtle
.bg-success-subtle
.bg-danger-subtle
.bg-warning-subtle
.bg-info-subtle
.bg-light-subtle
.bg-dark-subtle
html
<div class="p-3 mb-2 fw-bold bg-primary-subtle"><span class="text-bg-primary">.bg-primary-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-secondary-subtle"><span class="text-bg-secondary">.bg-secondary-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-success-subtle"><span class="text-bg-success">.bg-success-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-danger-subtle"><span class="text-bg-danger">.bg-danger-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-warning-subtle"><span class="text-bg-warning">.bg-warning-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-info-subtle"><span class="text-bg-info">.bg-info-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-light-subtle"><span class="text-bg-light">.bg-light-subtle</span></div>
<div class="p-3 mb-2 fw-bold bg-dark-subtle"><span class="text-bg-dark">.bg-dark-subtle</span></div>

Opacity

Added in v5.1.0

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.

How it works

Consider our default .bg-success utility.

.bg-success {
  --bs-bg-opacity: 1;
  background-color: rgba(var(--bs-success-rgb), var(--bs-bg-opacity)) !important;
}

We use an RGB version of our --bs-success (with the value of 25, 135, 84) CSS variable and attached a second CSS variable, --bs-bg-opacity, for the alpha transparency (with a default value 1 thanks to a local CSS variable). That means anytime you use .bg-success now, your computed color value is rgba(25, 135, 84, 1). The local CSS variable inside each .bg-* class avoids inheritance issues so nested instances of the utilities don’t automatically have a modified alpha transparency.

Example

To change that opacity, override --bs-bg-opacity via custom styles or inline styles.

This is default success background
This is 50% opacity success background
html
<div class="bg-success p-2 text-dark">This is default success background</div>
<div class="bg-success p-2" style="--bs-bg-opacity: .5;">This is 50% opacity success background</div>

Or, choose from any of the .bg-opacity utilities:

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
html
<div class="bg-success p-2 text-dark">This is default success background</div>
<div class="bg-success p-2 text-dark 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>

CSS

In addition to the following Sass functionality, consider reading about our included CSS custom properties (aka CSS variables) for colors and more.

Sass variables

Most background-color utilities are generated by our theme colors, reassigned from our generic color palette variables.

Boosted supersedes Bootstrap color variables with Orange brand color.

//// Functional colors
$functional-green:  $ods-forest-200;
$functional-blue:   $ods-water-200;
$functional-yellow: $ods-sun-100;
$functional-red:    $ods-fire-200;
//// Supporting colors
$supporting-blue:   $ods-blue-300;
$supporting-yellow: $ods-yellow-300;
$supporting-green:  $ods-green-300;
$supporting-purple: $ods-purple-300;
$supporting-pink:   $ods-pink-300;
$supporting-orange: $ods-orange-100;
$functional-green-dark:  $ods-forest-100;
$functional-blue-dark:   $ods-water-100;
$functional-yellow-dark: $functional-yellow;
$functional-red-dark:    $ods-fire-100;
$blue:    $functional-blue;
$indigo:  $supporting-purple;
$purple:  $supporting-purple;
$pink:    $supporting-pink;
$red:     $functional-red;
$orange:  $ods-orange-200;
$yellow:  $functional-yellow;
$green:   $functional-green;
$teal:    $supporting-green;
$cyan:    $supporting-blue;
$primary:       $orange;
$secondary:     $black;
$success:       $green;
$info:          $blue;
$warning:       $yellow;
$danger:        $red;
$light:         $gray-500;
$dark:          $black;
$primary-dark:    $supporting-orange;
$secondary-dark:  $white;
$success-dark:    $functional-green-dark;
$info-dark:       $functional-blue-dark;
$warning-dark:    $functional-yellow-dark;
$danger-dark:     $functional-red-dark;
$light-dark:      $gray-500;
$dark-dark:       $black;

Grayscale colors are also available, but only a subset are used to generate any utilities.

$white:    $ods-white-100;
$gray-100: #fafafa;
$gray-200: #f6f6f6;
$gray-300: $ods-gray-200;
$gray-400: $ods-gray-300;
$gray-500: $ods-gray-400;
$gray-600: $ods-gray-500;
$gray-700: $ods-gray-600;
$gray-800: $ods-gray-700;
$gray-900: $ods-gray-800;
$gray-950: $ods-gray-900;
$black:    $ods-black-900;

Variables for setting background-color in .bg-*-subtle utilities in light and dark mode:

$primary-bg-subtle:       $primary; // Boosted mod: instead of `tint-color($primary, 80%)`
$secondary-bg-subtle:     $secondary; // Boosted mod: instead of `tint-color($secondary, 80%)`
$success-bg-subtle:       $success; // Boosted mod: instead of `tint-color($success, 80%)`
$info-bg-subtle:          $info; // Boosted mod: instead of `tint-color($info, 80%)`
$warning-bg-subtle:       $warning; // Boosted mod: instead of `tint-color($warning, 80%)`
$danger-bg-subtle:        $danger; // Boosted mod: instead of `tint-color($danger, 80%)`
$light-bg-subtle:         $light; // Boosted mod: instead of `mix($gray-100, $white)`
$dark-bg-subtle:          $dark; // Boosted mod: instead of `$gray-400`
$primary-bg-subtle-dark:            $primary-dark; // Boosted mod: instead of `shade-color($primary, 80%)`
$secondary-bg-subtle-dark:          $secondary-dark; // Boosted mod: instead of `shade-color($secondary, 80%)`
$success-bg-subtle-dark:            $success-dark; // Boosted mod: instead of `shade-color($success, 80%)`
$info-bg-subtle-dark:               $info-dark; // Boosted mod: instead of `shade-color($info, 80%)`
$warning-bg-subtle-dark:            $warning-dark; // Boosted mod: instead of `shade-color($warning, 80%)`
$danger-bg-subtle-dark:             $danger-dark; // Boosted mod: instead of `shade-color($danger, 80%)`
$light-bg-subtle-dark:              $light-dark; // Boosted mod: instead of `$gray-800`
$dark-bg-subtle-dark:               $dark-dark; // Boosted mod: instead of `mix($gray-800, $black)`

Sass maps

Theme colors are then put into a Sass map so we can loop over them to generate our utilities, component modifiers, and more.

$theme-colors: (
  "primary":    $primary,
  "secondary":  $secondary,
  "success":    $success,
  "info":       $info,
  "warning":    $warning,
  "danger":     $danger,
  "light":      $light,
  "dark":       $dark
);
$theme-colors-dark: (
  "primary": $primary-dark,
  "secondary": $secondary-dark,
  "success": $success-dark,
  "info": $info-dark,
  "warning": $warning-dark,
  "danger": $danger-dark,
  "light": $light-dark,
  "dark": $dark-dark,
);

Grayscale colors are also available as a Sass map. This map is not used to generate any utilities.

$grays: (
  "100": $gray-100,
  "200": $gray-200,
  "300": $gray-300,
  "400": $gray-400,
  "500": $gray-500,
  "600": $gray-600,
  "700": $gray-700,
  "800": $gray-800,
  "900": $gray-900,
  "950": $gray-950,
);

RGB colors are generated from a separate Sass map:

$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
$theme-colors-rgb-dark: map-loop($theme-colors-dark, to-rgb, "$value");

Background color opacities build on that with their own map that’s consumed by the utilities API:

$utilities-bg: map-merge(
  $utilities-colors,
  (
    "black": to-rgb($black),
    "white": to-rgb($white),
    "body": to-rgb($body-bg)
  )
);
$utilities-bg-colors: map-loop($utilities-bg, rgba-css-var, "$key", "bg");

$utilities-bg-subtle: (
  "primary-subtle": var(--#{$prefix}primary-bg-subtle),
  "secondary-subtle": var(--#{$prefix}secondary-bg-subtle),
  "success-subtle": var(--#{$prefix}success-bg-subtle),
  "info-subtle": var(--#{$prefix}info-bg-subtle),
  "warning-subtle": var(--#{$prefix}warning-bg-subtle),
  "danger-subtle": var(--#{$prefix}danger-bg-subtle),
  "light-subtle": var(--#{$prefix}light-bg-subtle),
  "dark-subtle": var(--#{$prefix}dark-bg-subtle)
);

Color mode background colors are also available as a Sass map:

$theme-colors-bg-subtle: (
  "primary": $primary-bg-subtle,
  "secondary": $secondary-bg-subtle,
  "success": $success-bg-subtle,
  "info": $info-bg-subtle,
  "warning": $warning-bg-subtle,
  "danger": $danger-bg-subtle,
  "light": $light-bg-subtle,
  "dark": $dark-bg-subtle,
);
$theme-colors-bg-subtle-dark: (
  "primary": $primary-bg-subtle-dark,
  "secondary": $secondary-bg-subtle-dark,
  "success": $success-bg-subtle-dark,
  "info": $info-bg-subtle-dark,
  "warning": $warning-bg-subtle-dark,
  "danger": $danger-bg-subtle-dark,
  "light": $light-bg-subtle-dark,
  "dark": $dark-bg-subtle-dark,
);

Sass mixins

No mixins are used to generate our background utilities, but we do have some additional mixins for other situations where you’d like to create your own gradients.

@mixin gradient-bg($color: null) {
  background-color: $color;

  @if $enable-gradients {
    background-image: var(--#{$prefix}gradient);
  }
}

Sass utilities API

Background utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.

"background-color": (
  property: background-color,
  class: bg,
  local-vars: (
    "bg-opacity": 1
  ),
  values: map-merge(
    $utilities-bg-colors,
    (
      "transparent": transparent,
      "body-secondary": rgba(var(--#{$prefix}secondary-bg-rgb), var(--#{$prefix}bg-opacity)),
      "body-tertiary": rgba(var(--#{$prefix}tertiary-bg-rgb), var(--#{$prefix}bg-opacity)),
      "supporting-green": $supporting-green, // Boosted mod
      "supporting-blue": $supporting-blue, // Boosted mod
      "supporting-yellow": $supporting-yellow, // Boosted mod
      "supporting-pink": $supporting-pink, // Boosted mod
      "supporting-purple": $supporting-purple, // Boosted mod
      "supporting-orange": $supporting-orange, // Boosted mod
    )
  )
),
"bg-opacity": (
  css-var: true,
  class: bg-opacity,
  values: (
    10: .1,
    25: .25,
    50: .5,
    75: .75,
    100: 1
  )
),
"subtle-background-color": (
  property: background-color,
  class: bg,
  values: $utilities-bg-subtle
),