# 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](/helpers/colored-links/) which have `:hover` and `:focus` states.

```html

<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-body">.text-body</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>
```


**Deprecation:** With the addition of `.text-opacity-*` utilities and CSS variables for text utilities, `.text-black-50` and `.text-white-50` are deprecated as of v4.1.0. They'll be removed in v6.0.0.



##### Conveying meaning to assistive technologies

Relying on color to convey meaning creates a visual cue that assistive technologies, like screen readers, cannot perceive. It&#39;s essential that any information represented by color is either apparent from the content itself (e.g., the visible text) or supplemented by alternative methods, such as extra text using the `.visually-hidden` class.




## Opacity

<small class="d-inline-flex mb-3 px-2 py-1 fw-semibold text-success bg-success bg-opacity-10 border border-success border-opacity-10 rounded-2">Added in v4.1.0</small>


As of v4.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.

```css
.text-primary {
  --cui-text-opacity: 1;
  color: rgba(var(--cui-primary-rgb), var(--cui-text-opacity)) !important;
}
```

We use an RGB version of our `--cui-primary` (with the value of `13, 110, 253`) CSS variable and attached a second CSS variable, `--cui-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 `--cui-text-opacity` via custom styles or inline styles.

```html
<div class="text-primary">This is default primary text</div>
<div class="text-primary" style="--cui-text-opacity: .5;">This is 50% opacity primary text</div>
```

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

```html
<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](/customize/css-variables/) (aka CSS variables) for colors and more.

Do you need a gradient in your custom CSS? Just add `background-image: var(--cui-gradient);`.
### Variables

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

```scss
$blue:    #0d6efd;
$indigo:  #6610f2;
$purple:  #6f42c1;
$pink:    #d63384;
$red:     #dc3545;
$orange:  #fd7e14;
$yellow:  #ffc107;
$green:   #198754;
$teal:    #20c997;
$cyan:    #0dcaf0;

```

```scss
$primary:       #5856d6;
$secondary:     #6b7785;
$success:       #1b9e3e;
$info:          #39f;
$warning:       #f9b115;
$danger:        #e55353;
$light:         $gray-100;
$dark:          $gray-900;

```

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

```scss
$white:     #fff;
$gray-base: #323a49;
$gray-100:  #f3f4f7;
$gray-200:  #e7eaee;
$gray-300:  #dbdfe6;
$gray-400:  #cfd4de;
$gray-500:  #aab3c5;
$gray-600:  #6d7d9c;
$gray-700:  #4a566d;
$gray-800:  #323a49;
$gray-900:  #212631;
$black:     #080a0c;

```

### Map

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

```scss
$theme-colors: (
  &#34;primary&#34;:    $primary,
  &#34;secondary&#34;:  $secondary,
  &#34;success&#34;:    $success,
  &#34;info&#34;:       $info,
  &#34;warning&#34;:    $warning,
  &#34;danger&#34;:     $danger,
  &#34;light&#34;:      $light,
  &#34;dark&#34;:       $dark
);

```

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

```scss
$grays: (
  &#34;100&#34;: $gray-100,
  &#34;200&#34;: $gray-200,
  &#34;300&#34;: $gray-300,
  &#34;400&#34;: $gray-400,
  &#34;500&#34;: $gray-500,
  &#34;600&#34;: $gray-600,
  &#34;700&#34;: $gray-700,
  &#34;800&#34;: $gray-800,
  &#34;900&#34;: $gray-900
);

```

RGB colors are generated from a separate Sass map:

```scss
$theme-colors-rgb: map-loop($theme-colors, to-rgb, &#34;$value&#34;);

```

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

```scss
$utilities-text: map.merge(
  $utilities-colors,
  (
    &#34;black&#34;: to-rgb($black),
    &#34;white&#34;: to-rgb($white),
    &#34;body&#34;: to-rgb($body-color)
  )
);
$utilities-text-colors: map-loop($utilities-text, rgba-css-var, &#34;$prefix&#34;, &#34;$key&#34;, &#34;text&#34;);

$utilities-text-emphasis-colors: (
  &#34;primary-emphasis&#34;: var(--#{$prefix}primary-text-emphasis),
  &#34;secondary-emphasis&#34;: var(--#{$prefix}secondary-text-emphasis),
  &#34;success-emphasis&#34;: var(--#{$prefix}success-text-emphasis),
  &#34;info-emphasis&#34;: var(--#{$prefix}info-text-emphasis),
  &#34;warning-emphasis&#34;: var(--#{$prefix}warning-text-emphasis),
  &#34;danger-emphasis&#34;: var(--#{$prefix}danger-text-emphasis),
  &#34;light-emphasis&#34;: var(--#{$prefix}light-text-emphasis),
  &#34;dark-emphasis&#34;: var(--#{$prefix}dark-text-emphasis)
);

```

### Utilities API

Color utilities are declared in our utilities API in `scss/_utilities.scss`. [Learn how to use the utilities API.](/utilities/api/#using-the-api)

```scss
&#34;color&#34;: (
  property: color,
  class: text,
  dark-mode: true,
  local-vars: (
    &#34;text-opacity&#34;: 1
  ),
  values: map.merge(
    $utilities-text-colors,
    (
      &#34;muted&#34;: var(--#{$prefix}secondary-color), // deprecated
      &#34;black-50&#34;: rgba($black, .5), // deprecated
      &#34;white-50&#34;: rgba($white, .5), // deprecated
      &#34;body-secondary&#34;: var(--#{$prefix}secondary-color),
      &#34;body-tertiary&#34;: var(--#{$prefix}tertiary-color),
      &#34;body-emphasis&#34;: var(--#{$prefix}emphasis-color),
      &#34;reset&#34;: inherit,
      &#34;high-emphasis-inverse&#34;: var(--#{$prefix}high-emphasis-inverse), // deprecated
      &#34;medium-emphasis-inverse&#34;: var(--#{$prefix}medium-emphasis-inverse), // deprecated
      &#34;disabled-inverse&#34;: var(--#{$prefix}disabled-inverse), // deprecated
      &#34;high-emphasis&#34;: var(--#{$prefix}high-emphasis), // deprecated
      &#34;medium-emphasis&#34;: var(--#{$prefix}medium-emphasis), // deprecated
      &#34;disabled&#34;: var(--#{$prefix}disabled)
    )
  )
),
&#34;text-opacity&#34;: (
  css-var: true,
  class: text-opacity,
  values: (
    25: .25,
    50: .5,
    75: .75,
    100: 1
  )
),
&#34;text-color&#34;: (
  property: color,
  class: text,
  values: $utilities-text-emphasis-colors
),
```
