Bootstrap includes around two dozen CSS custom properties (variables) in its compiled CSS, with dozens more on the way for improved customization on a per-component basis. These provide easy access to commonly used values like our theme colors, breakpoints, and primary font stacks when working in your browser’s inspector, a code sandbox, or general prototyping.

All our custom properties are prefixed with bs- to avoid conflicts with third party CSS.

Root variables

Here are the variables we include (note that the :root is required) that can be accessed anywhere Bootstrap’s CSS is loaded. They’re located in our _root.scss file and included in our compiled dist files.

  1. :root {
  2. --bs-blue: #0d6efd;
  3. --bs-indigo: #6610f2;
  4. --bs-purple: #6f42c1;
  5. --bs-pink: #d63384;
  6. --bs-red: #dc3545;
  7. --bs-orange: #fd7e14;
  8. --bs-yellow: #ffc107;
  9. --bs-green: #198754;
  10. --bs-teal: #20c997;
  11. --bs-cyan: #0dcaf0;
  12. --bs-white: #fff;
  13. --bs-gray: #6c757d;
  14. --bs-gray-dark: #343a40;
  15. --bs-primary: #0d6efd;
  16. --bs-secondary: #6c757d;
  17. --bs-success: #198754;
  18. --bs-info: #0dcaf0;
  19. --bs-warning: #ffc107;
  20. --bs-danger: #dc3545;
  21. --bs-light: #f8f9fa;
  22. --bs-dark: #212529;
  23. --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  24. --bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  25. --bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
  26. }

Component variables

We’re also beginning to make use of custom properties as local variables for various components. This way we can reduce our compiled CSS, ensure styles aren’t inherited in places like nested tables, and allow some basic restyling and extending of Bootstrap components after Sass compilation.

Have a look at our table documentation for some insight into how we’re using CSS variables.

We’re also using CSS variables across our grids—primarily for gutters—with more component usage coming in the future.

Examples

CSS variables offer similar flexibility to Sass’s variables, but without the need for compilation before being served to the browser. For example, here we’re resetting our page’s font and link styles with CSS variables.

  1. body {
  2. font: 1rem/1.5 var(--bs-font-sans-serif);
  3. }
  4. a {
  5. color: var(--bs-blue);
  6. }