Colors
Convey meaning through color
with a handful of color utility classes. Includes support for styling links with hover states, too.
Colors
Colorize text with color utilities. If you want to colorize links, you can use the .link-*
helper classes which have :hover
and :focus
states.
.text-primary
.text-primary-emphasis
.text-secondary
.text-secondary-emphasis
.text-success
.text-success-emphasis
.text-danger
.text-danger-emphasis
.text-warning
.text-warning-emphasis
.text-info
.text-info-emphasis
.text-light
.text-light-emphasis
.text-dark
.text-dark-emphasis
.text-body
.text-muted
.text-body-emphasis
.text-body-secondary
.text-body-tertiary
.text-black
.text-white
.text-black-50
.text-white-50
<p class="text-primary">.text-primary</p>
<p class="text-primary-emphasis">.text-primary-emphasis</p>
<p class="text-secondary">.text-secondary</p>
<p class="text-secondary-emphasis">.text-secondary-emphasis</p>
<p class="text-success">.text-success</p>
<p class="text-success-emphasis">.text-success-emphasis</p>
<p class="text-danger">.text-danger</p>
<p class="text-danger-emphasis">.text-danger-emphasis</p>
<p class="text-warning bg-dark">.text-warning</p>
<p class="text-warning-emphasis">.text-warning-emphasis</p>
<p class="text-info bg-dark">.text-info</p>
<p class="text-info-emphasis">.text-info-emphasis</p>
<p class="text-light bg-dark">.text-light</p>
<p class="text-light-emphasis">.text-light-emphasis</p>
<p class="text-dark bg-white">.text-dark</p>
<p class="text-dark-emphasis">.text-dark-emphasis</p>
<p class="text-body">.text-body</p>
<p class="text-muted">.text-muted</p>
<p class="text-body-emphasis">.text-body-emphasis</p>
<p class="text-body-secondary">.text-body-secondary</p>
<p class="text-body-tertiary">.text-body-tertiary</p>
<p class="text-black bg-white">.text-black</p>
<p class="text-white bg-dark">.text-white</p>
<p class="text-black-50 bg-white">.text-black-50</p>
<p class="text-white-50 bg-dark">.text-white-50</p>
.text-opacity-*
utilities and CSS variables for text utilities, .text-black-50
and .text-white-50
are deprecated as of v5.1.0. They’ll be removed in v6.0.0.
.text-muted
utility has been deprecated as of v5.3.0. Its default value has also has been reassigned to the new --bs-secondary-color
CSS variable to better support color modes. It will be removed in v6.0.0.
.visually-hidden
class.
Opacity
Added in v5.1.0As of v5.1.0, text 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 .text-primary
utility.
.text-primary {
--bs-text-opacity: 1;
color: rgba(var(--bs-primary-rgb), var(--bs-text-opacity)) !important;
}
We use an RGB version of our --bs-primary
(with the value of 13, 110, 253
) CSS variable and attached a second CSS variable, --bs-text-opacity
, for the alpha transparency (with a default value 1
thanks to a local CSS variable). That means anytime you use .text-primary
now, your computed color
value is rgba(13, 110, 253, 1)
. The local CSS variable inside each .text-*
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-text-opacity
via custom styles or inline styles.
<div class="text-primary">This is default primary text</div>
<div class="text-primary" style="--bs-text-opacity: .5;">This is 50% opacity primary text</div>
Or, choose from any of the .text-opacity
utilities:
<div class="text-primary">This is default primary text</div>
<div class="text-primary text-opacity-75">This is 75% opacity primary text</div>
<div class="text-primary text-opacity-50">This is 50% opacity primary text</div>
<div class="text-primary text-opacity-25">This is 25% opacity primary text</div>
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>
or more semantic element with the desired class.
Sass
In addition to the following Sass functionality, consider reading about our included CSS custom properties (aka CSS variables) for colors and more.
Variables
Most color
utilities are generated by our theme colors, reassigned from our generic color palette variables.
$blue: #007797;
$indigo: #6610f2;
$purple: #6f42c1;
$pink: #d63384;
$red: #db0007;
$orange: #fd7e14;
$yellow: #ffbc0d;
$green: #508e00;
$teal: #20c997;
$cyan: #0dcaf0;
$dark-green: #234e33;
$gold: #ffbc0d;
$primary: $dark-green;
$secondary: $gold;
$success: $green;
$info: $blue;
$warning: $gold;
$danger: $red;
$light: $light-gray;
$dark: $dark-gray;
$tables-color: #292928;
Grayscale colors are also available, but only a subset are used to generate any utilities.
$white: #fff;
$gray-10: #fbfbfb;
$gray-30: #f6f6f6;
$gray-50: #f2f2f2;
$gray-100: #ededed;
$gray-200: #dcdcdc;
$gray-300: #cacaca;
$gray-400: #b9b9b9;
$gray-500: #a7a7a7;
$gray-600: #868686;
$gray-700: #646464;
$gray-800: #434343;
$gray-900: #212121;
$black: #000;
$light-gray: #f7f7f7;
$dark-gray: #636363;
Map
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-gray,
"dark": $dark-gray
);
//$alerts-theme-colors: (
// "primary": $light-gray,
// "secondary": $secondary,
// "success": $success,
// "info": $info,
// "warning": $warning,
// "danger": $danger,
// "light": $light-gray,
// "dark": $dark-gray
//);
Grayscale colors are also available as a Sass map. This map is not used to generate any utilities.
$grays: (
"10": $gray-10,
"30": $gray-30,
"50": $gray-50,
"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,
"light": $light-gray,
"dark": $dark-gray
);
RGB colors are generated from a separate Sass map:
$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
And color opacities build on that with their own map that’s consumed by the utilities API:
$utilities-text: map-merge(
$utilities-colors,
(
"black": to-rgb($black),
"white": to-rgb($white),
"body": to-rgb($body-color)
)
);
$utilities-text-colors: map-loop($utilities-text, rgba-css-var, "$key", "text");
$utilities-text-emphasis-colors: (
"primary-emphasis": var(--#{$prefix}primary-text),
"secondary-emphasis": var(--#{$prefix}secondary-text),
"success-emphasis": var(--#{$prefix}success-text),
"info-emphasis": var(--#{$prefix}info-text),
"warning-emphasis": var(--#{$prefix}warning-text),
"danger-emphasis": var(--#{$prefix}danger-text),
"light-emphasis": var(--#{$prefix}light-text),
"dark-emphasis": var(--#{$prefix}dark-text)
);
Utilities API
Color utilities are declared in our utilities API in scss/_utilities.scss
. Learn how to use the utilities API.
"color": (
property: color,
class: text,
local-vars: (
"text-opacity": 1
),
values: map-merge(
$utilities-text-colors,
(
"muted": $text-muted, // deprecated
"black-50": rgba($black, .5), // deprecated
"white-50": rgba($white, .5), // deprecated
"body-secondary": var(--#{$prefix}secondary-color),
"body-tertiary": var(--#{$prefix}tertiary-color),
"body-emphasis": var(--#{$prefix}emphasis-color),
"reset": inherit,
)
)
),
"text-opacity": (
css-var: true,
class: text-opacity,
values: (
25: .25,
50: .5,
75: .75,
100: 1
)
),
"text-color": (
property: color,
class: text,
values: $utilities-text-emphasis-colors
),