Color
CoreUI for Bootstrap is supported by an extensive color system that themes our styles and components. This enables more comprehensive customization and extension for any project.
Colors
Added in v5.0.0Bootstrap’s color palette has continued to expand and become more nuanced in v5.0.0. We’ve added new variables for secondary
and tertiary
text and background colors, plus {color}-bg-subtle
, {color}-border-subtle
, and {color}-text-emphasis
for our theme colors. These new colors are available through Sass and CSS variables (but not our color maps or utility classes) with the express goal of making it easier to customize across multiple colors modes like light and dark. These new variables are globally set on :root
and are adapted for our new dark color mode while our original theme colors remain unchanged.
Colors ending in -rgb
provide the red, green, blue
values for use in rgb()
and rgba()
color modes. For example, rgba(var(--cui-secondary-bg-rgb), .5)
.
Description | Swatch | Variables |
---|---|---|
Body — Default foreground (color) and background, including components. |
|
--cui-body-color --cui-body-color-rgb
|
|
--cui-body-bg --cui-body-bg-rgb
|
|
Secondary — Use the color option for lighter text. Use the bg option for dividers and to indicate disabled component states.
|
|
--cui-secondary-color --cui-secondary-color-rgb
|
|
--cui-secondary-bg --cui-secondary-bg-rgb
|
|
Tertiary — Use the color option for even lighter text. Use the bg option to style backgrounds for hover states, accents, and wells.
|
|
--cui-tertiary-color --cui-tertiary-color-rgb
|
|
--cui-tertiary-bg --cui-tertiary-bg-rgb
|
|
Emphasis — For higher contrast text. Not applicable for backgrounds. |
|
--cui-emphasis-color --cui-emphasis-color-rgb
|
Border — For component borders, dividers, and rules. Use --cui-border-color-translucent to blend with backgrounds with an rgba() value.
|
|
--cui-border-color --cui-border-color-rgb
|
Primary — Main theme color, used for hyperlinks, focus styles, and component and form active states. |
|
--cui-primary --cui-primary-rgb
|
|
--cui-primary-bg-subtle
|
|
|
--cui-primary-border-subtle
|
|
Text
|
--cui-primary-text-emphasis
|
|
Success — Theme color used for positive or successful actions and information. |
|
--cui-success --cui-success-rgb
|
|
--cui-success-bg-subtle
|
|
|
--cui-success-border-subtle
|
|
Text
|
--cui-success-text-emphasis
|
|
Danger — Theme color used for errors and dangerous actions. |
|
--cui-danger --cui-danger-rgb
|
|
--cui-danger-bg-subtle
|
|
|
--cui-danger-border-subtle
|
|
Text
|
--cui-danger-text-emphasis
|
|
Warning — Theme color used for non-destructive warning messages. |
|
--cui-warning --cui-warning-rgb
|
|
--cui-warning-bg-subtle
|
|
|
--cui-warning-border-subtle
|
|
Text
|
--cui-warning-text-emphasis
|
|
Info — Theme color used for neutral and informative content. |
|
--cui-info --cui-info-rgb
|
|
--cui-info-bg-subtle
|
|
|
--cui-info-border-subtle
|
|
Text
|
--cui-info-text-emphasis
|
|
Light — Additional theme option for less contrasting colors. |
|
--cui-light --cui-light-rgb
|
|
--cui-light-bg-subtle
|
|
|
--cui-light-border-subtle
|
|
Text
|
--cui-light-text-emphasis
|
|
Dark — Additional theme option for higher contrasting colors. |
|
--cui-dark --cui-dark-rgb
|
|
--cui-dark-bg-subtle
|
|
|
--cui-dark-border-subtle
|
|
Text
|
--cui-dark-text-emphasis
|
Using the new colors
These new colors are accessible via CSS variables and utility classes—like --cui-primary-bg-subtle
and .bg-primary-subtle
—allowing you to compose your own CSS rules with the variables, or to quickly apply styles via classes. The utilities are built with the color’s associated CSS variables, and since we customize those CSS variables for dark mode, they are also adaptive to color mode by default.
<div class="p-3 text-primary-emphasis bg-primary-subtle border border-primary-subtle rounded-3">
Example element with utilities
</div>
Theme colors
We use a subset of all colors to create a smaller color palette for generating color schemes, also available as Sass variables and a Sass map in CoreUI for Bootstrap’s scss/_variables.scss
file.
All these colors are available as a Sass map, $theme-colors
.
$theme-colors: (
"primary": $primary,
"secondary": $secondary,
"success": $success,
"info": $info,
"warning": $warning,
"danger": $danger,
"light": $light,
"dark": $dark
);
Check out our Sass maps and loops docs for how to modify these colors.
All colors
All CoreUI for Bootstrap colors are available as Sass variables and a Sass map in scss/_variables.scss
file. To avoid increased file sizes, we don’t create text or background color classes for each of these variables. Instead, we choose a subset of these colors for a theme palette.
Be sure to monitor contrast ratios as you customize colors. As shown below, we’ve added three contrast ratios to each of the main colors—one for the swatch’s current colors, one for against white, and one for against black.
Notes on Sass
Sass cannot programmatically generate variables, so we manually created variables for every tint and shade ourselves. We specify the midpoint value (e.g., $blue-500
) and use custom color functions to tint (lighten) or shade (darken) our colors via Sass’s mix()
color function.
Using mix()
is not the same as lighten()
and darken()
—the former blends the specified color with white or black, while the latter only adjusts the lightness value of each color. The result is a much more complete suite of colors, as shown in this CodePen demo.
Our tint-color()
and shade-color()
functions use mix()
alongside our $theme-color-interval
variable, which specifies a stepped percentage value for each mixed color we produce. See the scss/_functions.scss
and scss/_variables.scss
files for the full source code.
Color Sass maps
CoreUI for Bootstrap’s source Sass files include three maps to help you quickly and easily loop over a list of colors and their hex values.
$colors
lists all our available base (500
) colors$theme-colors
lists all semantically named theme colors (shown below)$grays
lists all tints and shades of gray
Within scss/_variables.scss
, you’ll find CoreUI for Bootstrap’s color variables and Sass map. Here’s an example of the $colors
Sass map:
$colors: (
"blue": $blue,
"indigo": $indigo,
"purple": $purple,
"pink": $pink,
"red": $red,
"orange": $orange,
"yellow": $yellow,
"green": $green,
"teal": $teal,
"cyan": $cyan,
"black": $black,
"white": $white,
"gray": $gray-600,
"gray-dark": $gray-800
);
Add, remove, or modify values within the map to update how they’re used in many other components. Unfortunately at this time, not every component utilizes this Sass map. Future updates will strive to improve upon this. Until then, plan on making use of the ${color}
variables and this Sass map.
Example
Here’s how you can use these in your Sass:
.alpha { color: $purple; }
.beta {
color: $yellow-300;
background-color: $indigo-900;
}
Color and background utility classes are also available for setting color
and background-color
using the 500
color values.
Generating utilities
Added in v4.1.0Bootstrap doesn’t include color
and background-color
utilities for every color variable, but you can generate these yourself with our utility API and our extended Sass maps added in v4.1.0.
- To start, make sure you’ve imported our functions, variables, mixins, and utilities.
- Use our
map-merge-multiple()
function to quickly merge multiple Sass maps together in a new map. - Merge this new combined map to extend any utility with a
{color}-{level}
class name.
Here’s an example that generates text color utilities (e.g., .text-purple-500
) using the above steps.
@import "@coreui/coreui/scss/functions";
@import "@coreui/coreui/scss/variables";
@import "@coreui/coreui/scss/maps";
@import "@coreui/coreui/scss/mixins";
@import "@coreui/coreui/scss/utilities";
$all-colors: map-merge-multiple($blues, $indigos, $purples, $pinks, $reds, $oranges, $yellows, $greens, $teals, $cyans);
$utilities: map-merge(
$utilities,
(
"color": map-merge(
map-get($utilities, "color"),
(
values: map-merge(
map-get(map-get($utilities, "color"), "values"),
(
$all-colors
),
),
),
),
)
);
@import "@coreui/coreui/scss/utilities/api";
This will generate new .text-{color}-{level}
utilities for every color and level. You can do the same for any other utility and property as well.