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.

Colors - 图1

  1. <p class="text-primary">.text-primary</p>
  2. <p class="text-secondary">.text-secondary</p>
  3. <p class="text-success">.text-success</p>
  4. <p class="text-danger">.text-danger</p>
  5. <p class="text-warning bg-dark">.text-warning</p>
  6. <p class="text-info bg-dark">.text-info</p>
  7. <p class="text-light bg-dark">.text-light</p>
  8. <p class="text-dark">.text-dark</p>
  9. <p class="text-body">.text-body</p>
  10. <p class="text-muted">.text-muted</p>
  11. <p class="text-white bg-dark">.text-white</p>
  12. <p class="text-black-50">.text-black-50</p>
  13. <p class="text-white-50 bg-dark">.text-white-50</p>
Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden class.

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.

  1. $blue: #0d6efd;
  2. $indigo: #6610f2;
  3. $purple: #6f42c1;
  4. $pink: #d63384;
  5. $red: #dc3545;
  6. $orange: #fd7e14;
  7. $yellow: #ffc107;
  8. $green: #198754;
  9. $teal: #20c997;
  10. $cyan: #0dcaf0;
  1. $primary: $blue;
  2. $secondary: $gray-600;
  3. $success: $green;
  4. $info: $cyan;
  5. $warning: $yellow;
  6. $danger: $red;
  7. $light: $gray-100;
  8. $dark: $gray-900;

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

  1. $white: #fff;
  2. $gray-100: #f8f9fa;
  3. $gray-200: #e9ecef;
  4. $gray-300: #dee2e6;
  5. $gray-400: #ced4da;
  6. $gray-500: #adb5bd;
  7. $gray-600: #6c757d;
  8. $gray-700: #495057;
  9. $gray-800: #343a40;
  10. $gray-900: #212529;
  11. $black: #000;

Map

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

  1. $theme-colors: (
  2. "primary": $primary,
  3. "secondary": $secondary,
  4. "success": $success,
  5. "info": $info,
  6. "warning": $warning,
  7. "danger": $danger,
  8. "light": $light,
  9. "dark": $dark
  10. );

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

  1. $grays: (
  2. "100": $gray-100,
  3. "200": $gray-200,
  4. "300": $gray-300,
  5. "400": $gray-400,
  6. "500": $gray-500,
  7. "600": $gray-600,
  8. "700": $gray-700,
  9. "800": $gray-800,
  10. "900": $gray-900
  11. );

Utilities API

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

  1. "color": (
  2. property: color,
  3. class: text,
  4. values: map-merge(
  5. $theme-colors,
  6. (
  7. "white": $white,
  8. "body": $body-color,
  9. "muted": $text-muted,
  10. "black-50": rgba($black, .5),
  11. "white-50": rgba($white, .5),
  12. "reset": inherit,
  13. )
  14. )
  15. ),