View on GitHub

CSS variables

Use Boosted’s CSS custom properties for fast and forward-looking design and development.

Boosted includes many CSS custom properties (variables) in its compiled CSS for real-time customization without the need to recompile Sass. 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 Boosted’s CSS is loaded. They’re located in our _root.scss file and included in our compiled dist files.

:root {
  --bs-blue: #527edb;
  --bs-indigo: #a885d8;
  --bs-purple: #a885d8;
  --bs-pink: #ffb4e6;
  --bs-red: #cd3c14;
  --bs-orange: #ff7900;
  --bs-yellow: #fc0;
  --bs-green: #32c832;
  --bs-teal: #50be87;
  --bs-cyan: #4bb4e6;
  --bs-black: #000;
  --bs-white: #fff;
  --bs-gray: #999;
  --bs-gray-dark: #595959;
  --bs-gray-100: #fafafa;
  --bs-gray-200: #f6f6f6;
  --bs-gray-300: #eee;
  --bs-gray-400: #ddd;
  --bs-gray-500: #ccc;
  --bs-gray-600: #999;
  --bs-gray-700: #666;
  --bs-gray-800: #595959;
  --bs-gray-900: #333;
  --bs-primary: #ff7900;
  --bs-secondary: #000;
  --bs-success: #32c832;
  --bs-info: #527edb;
  --bs-warning: #fc0;
  --bs-danger: #cd3c14;
  --bs-light: #ccc;
  --bs-dark: #000;
  --bs-primary-rgb: 255, 121, 0;
  --bs-secondary-rgb: 0, 0, 0;
  --bs-success-rgb: 50, 200, 50;
  --bs-info-rgb: 82, 126, 219;
  --bs-warning-rgb: 255, 204, 0;
  --bs-danger-rgb: 205, 60, 20;
  --bs-light-rgb: 204, 204, 204;
  --bs-dark-rgb: 0, 0, 0;
  --bs-primary-text-rgb: 241, 110, 0;
  --bs-white-rgb: 255, 255, 255;
  --bs-black-rgb: 0, 0, 0;
  --bs-body-color-rgb: 0, 0, 0;
  --bs-body-bg-rgb: 255, 255, 255;
  --o-chevron-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 14'%3e%3cpath d='M9 2 7 0 0 7l7 7 2-2-5-5 5-5z'/%3e%3c/svg%3e");
  --o-close-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='116 116 767 767' fill='%23000'%3e%3cpath d='M817.493 676.165a49.977 49.977 0 0 1 0 70.664l-70.664 70.664a49.977 49.977 0 0 1-70.664 0L499.5 640.828 322.835 817.493a49.977 49.977 0 0 1-70.664 0l-70.664-70.664a49.977 49.977 0 0 1 0-70.664L358.172 499.5 181.507 322.835a49.977 49.977 0 0 1 0-70.664l70.664-70.664a49.977 49.977 0 0 1 70.664 0L499.5 358.172l176.665-176.665a49.977 49.977 0 0 1 70.664 0l70.664 70.664a49.977 49.977 0 0 1 0 70.664L640.828 499.5Z'/%3e%3c/svg%3e");
  --o-check-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 12'%3e%3cpath fill='%23000' d='M13 0 5 8 2 5 0 7l5 5L15 2z'/%3e%3c/svg%3e");
  --o-success-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 125 125'%3e%3cpath fill='%2332c832' d='M62.5 0a62.5 62.5 0 1 0 0 125 62.5 62.5 0 0 0 0-125zm28 29.4c3.3 0 6 2.6 6 5.9a5.9 5.9 0 0 1-1.3 3.7L57.7 86a5.8 5.8 0 0 1-9.1 0L29.8 62.5c-.8-1-1.2-2.3-1.2-3.7a5.9 5.9 0 0 1 1.7-4.1l2.3-2.4a5.8 5.8 0 0 1 4.2-1.7 5.8 5.8 0 0 1 3.8 1.4L52 64.7 86.6 31a5.8 5.8 0 0 1 4-1.6z'/%3e%3c/svg%3e");
  --o-error-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 125'%3e%3cpath fill='%23cd3c14' d='M70.3 0c-5.8 0-10.8 3.1-13.5 7.8L2.3 101.3l-.2.2A15.6 15.6 0 0 0 15.6 125H125a15.6 15.6 0 0 0 13.5-23.5L83.8 7.8A15.6 15.6 0 0 0 70.3 0zm19.2 50a6.4 6.4 0 0 1 4.4 1.9 6.4 6.4 0 0 1 0 9L79.4 75.6l15 15a6.4 6.4 0 0 1 0 9.2 6.4 6.4 0 0 1-4.5 1.9 6.4 6.4 0 0 1-4.6-2l-15-15-15 15a6.4 6.4 0 0 1-4.6 2 6.4 6.4 0 0 1-4.6-2 6.4 6.4 0 0 1 0-9l15-15L46.8 61a6.4 6.4 0 1 1 9-9.1l14.6 14.5L84.8 52a6.4 6.4 0 0 1 4.7-1.9z'/%3e%3c/svg%3e");
  --bs-font-sans-serif: HelvNeueOrange/*rtl:insert:Arabic*/, "Helvetica Neue", Helvetica, "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
  --bs-body-font-family: var(--bs-font-sans-serif);
  --bs-body-font-size: 1rem;
  --bs-body-font-weight: 400;
  --bs-body-line-height: 1.125;
  --bs-body-color: #000;
  --bs-body-bg: #fff;
  --bs-border-width: 0.125rem;
  --bs-border-style: solid;
  --bs-border-color: #000;
  --bs-border-color-translucent: #ccc;
  --bs-border-radius: ;
  --bs-border-radius-sm: ;
  --bs-border-radius-lg: ;
  --bs-border-radius-xl: ;
  --bs-border-radius-2xl: ;
  --bs-border-radius-pill: 50rem;
  --bs-link-color: #000;
  --bs-link-hover-color: #f16e00;
  --bs-focus-visible-inner-color: #fff;
  --bs-focus-visible-outer-color: #000;
  --bs-code-color: #666;
  --bs-highlight-color: #fff;
  --bs-highlight-bg: #000;
}

Component variables

Boosted 5 is increasingly making use of custom properties as local variables for various components. This way we reduce our compiled CSS, ensure styles aren’t inherited in places like nested tables, and allow some basic restyling and extending of Boosted components after Sass compilation.

Have a look at our table documentation for some insight into how we’re using CSS variables. Our navbars also use CSS variables as of v5.2.0. We’re also using CSS variables across our grids—primarily for gutters the new opt-in CSS grid—with more component usage coming in the future.

Whenever possible, we’ll assign CSS variables at the base component level (e.g., .navbar for navbar and its sub-components). This reduces guessing on where and how to customize, and allows for easy modifications by our team in future updates.

Dark text rule

Using CSS variables allows a better flexibility on certain rules. This way we adapt our text variant color to our dark variants components instead of rewriting rules for each component. This process implies to override some existing CSS variables and to re-initialize those in some cases.

Here is our proposal to handle the different text variants over the website:

// Boosted mod
[class*="bg-black"],
[class*="-dark"]:not(.border-dark):not(.text-dark):not(.btn-dark),
[class*="bg-secondary"] {
  --#{$prefix}primary-text-rgb: #{to-rgb($brand-orange)};
  --#{$prefix}link-color: #{$link-color-dark};
  --#{$prefix}link-hover-color: #{$link-hover-color-dark};
  --#{$prefix}focus-visible-inner-color: #{$focus-visible-inner-color-dark};
  --#{$prefix}focus-visible-outer-color: #{$focus-visible-outer-color-dark};
  --#{$boosted-prefix}caption-color: #{$table-caption-color-dark};
  --#{$prefix}code-color: #{$code-color-dark};
  --#{$prefix}highlight-color: #{$mark-color-dark};
  --#{$prefix}highlight-bg: #{$mark-bg-dark};
  --#{$boosted-prefix}kbd-color: #{$kbd-color-dark};
  --#{$boosted-prefix}kbd-bg: #{$kbd-bg-dark};
  --#{$boosted-prefix}pre-color: #{$pre-color-dark};

  // stylelint-disable-next-line scss/selector-no-redundant-nesting-selector
  [class*="bg-"]:not(&):not(.bg-transparent) {
    --#{$prefix}primary-text-rgb: #{to-rgb($accessible-orange)};
    --#{$prefix}link-color: #{$link-color};
    --#{$prefix}link-hover-color: #{$link-hover-color};
    --#{$prefix}focus-visible-inner-color: #{$focus-visible-inner-color};
    --#{$prefix}focus-visible-outer-color: #{$focus-visible-outer-color};
    --#{$boosted-prefix}caption-color: #{$table-caption-color};
    --#{$prefix}code-color: #{$code-color};
    --#{$prefix}highlight-color: #{$mark-color};
    --#{$prefix}highlight-bg: #{$mark-bg};
    --#{$boosted-prefix}kbd-color: #{$kbd-color};
    --#{$boosted-prefix}kbd-bg: #{$kbd-bg};
    --#{$boosted-prefix}pre-color: #{$pre-color};
  }
}
// End mod

Prefix

Most CSS variables use a prefix to avoid collisions with your own codebase. This prefix is in addition to the -- that’s required on every CSS variable.

Customize the prefix via the $prefix Sass variable. By default, it’s set to bs- (note the trailing dash).

Deduping embedded SVGs

Boosted uses embedded SVGs as data URIs in the wild, which means extremely long strings in CSS. When one of them is used several times in the stylesheet, CSS custom properties allows to factorize its string— thus to decrease output file size.

:root {
  --o-chevron-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 14'%3e%3cpath d='M9 2L7 0 0 7l7 7 2-2-5-5 5-5z'/%3e%3c/svg%3e");
}

.back-to-top-link::after {
  background-image: var(--o-chevron-icon);
}

.pagination-item:first-child .page-link::before {
  background-image: var(--o-chevron-icon);
}

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.

body {
  font: 1rem/1.5 var(--bs-font-sans-serif);
}
a {
  color: var(--bs-blue);
}

Grid breakpoints

While we include our grid breakpoints as CSS variables (except for xs), be aware that CSS variables do not work in media queries. This is by design in the CSS spec for variables, but may change in coming years with support for env() variables. Check out this Stack Overflow answer for some helpful links. In the meantime, you can use these variables in other CSS situations, as well as in your JavaScript.