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.
Default
These CSS variables are available everywhere, regardless of color mode.
:root,
[data-bs-theme=light] {
color-scheme: light;
--bs-blue: #4170d8;
--bs-indigo: #a885d8;
--bs-purple: #a885d8;
--bs-pink: #ffb4e6;
--bs-red: #cd3c14;
--bs-orange: #f16e00;
--bs-yellow: #fc0;
--bs-green: #228722;
--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-gray-950: #141414;
--bs-primary: #f16e00;
--bs-secondary: #000;
--bs-success: #228722;
--bs-info: #4170d8;
--bs-warning: #fc0;
--bs-danger: #cd3c14;
--bs-light: #ccc;
--bs-dark: #000;
--bs-primary-rgb: 241, 110, 0;
--bs-secondary-rgb: 0, 0, 0;
--bs-success-rgb: 34, 135, 34;
--bs-info-rgb: 65, 112, 216;
--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-emphasis: #f16e00;
--bs-secondary-text-emphasis: #000;
--bs-success-text-emphasis: #228722;
--bs-info-text-emphasis: #4170d8;
--bs-warning-text-emphasis: #fc0;
--bs-danger-text-emphasis: #cd3c14;
--bs-light-text-emphasis: #ccc;
--bs-dark-text-emphasis: #000;
--bs-primary-bg-subtle: #f16e00;
--bs-secondary-bg-subtle: #000;
--bs-success-bg-subtle: #228722;
--bs-info-bg-subtle: #4170d8;
--bs-warning-bg-subtle: #fc0;
--bs-danger-bg-subtle: #cd3c14;
--bs-light-bg-subtle: #ccc;
--bs-dark-bg-subtle: #000;
--bs-primary-border-subtle: #f16e00;
--bs-secondary-border-subtle: #000;
--bs-success-border-subtle: #228722;
--bs-info-border-subtle: #4170d8;
--bs-warning-border-subtle: #fc0;
--bs-danger-border-subtle: #cd3c14;
--bs-light-border-subtle: #ccc;
--bs-dark-border-subtle: #000;
--bs-white-rgb: 255, 255, 255;
--bs-black-rgb: 0, 0, 0;
--bs-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");
--bs-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");
--bs-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");
--bs-success-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 125 125'%3e%3cpath fill='%23228722' 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");
--bs-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-color-rgb: 0, 0, 0;
--bs-body-bg: #fff;
--bs-body-bg-rgb: 255, 255, 255;
--bs-emphasis-color: #000;
--bs-emphasis-color-rgb: 0, 0, 0;
--bs-secondary-color: #666;
--bs-secondary-color-rgb: 102, 102, 102;
--bs-secondary-bg: #eee;
--bs-secondary-bg-rgb: 238, 238, 238;
--bs-tertiary-color: #ccc;
--bs-tertiary-color-rgb: 204, 204, 204;
--bs-tertiary-bg: #fafafa;
--bs-tertiary-bg-rgb: 250, 250, 250;
--bs-heading-color: inherit;
--bs-link-color: #000;
--bs-link-color-rgb: 0, 0, 0;
--bs-link-decoration: underline;
--bs-link-hover-color: #f16e00;
--bs-link-hover-color-rgb: 241, 110, 0;
--bs-code-color: #666;
--bs-highlight-color: #fff;
--bs-highlight-bg: #000;
--bs-disabled-color: var(--bs-tertiary-color);
--bs-tertiary-active-bg: #ddd;
--bs-border-width: 0.125rem;
--bs-border-style: solid;
--bs-border-color: #000;
--bs-border-color-subtle: #ccc;
--bs-border-color-translucent: rgba(0, 0, 0, 0.175);
--bs-border-radius: 0.375rem;
--bs-border-radius-sm: 0.25rem;
--bs-border-radius-lg: 0.5rem;
--bs-border-radius-xl: 1rem;
--bs-border-radius-xxl: 2rem;
--bs-border-radius-2xl: var(--bs-border-radius-xxl);
--bs-border-radius-pill: 50rem;
--bs-box-shadow: ;
--bs-box-shadow-sm: ;
--bs-box-shadow-lg: ;
--bs-box-shadow-inset: ;
--bs-focus-visible-inner-color: #fff;
--bs-focus-visible-outer-color: #000;
--bs-focus-ring-width: 0.25rem;
--bs-focus-ring-opacity: 0.25;
--bs-focus-ring-color: rgba(241, 110, 0, 0.25);
--bs-form-valid-color: var(--bs-success-text-emphasis);
--bs-form-valid-border-color: var(--bs-success);
--bs-form-invalid-color: var(--bs-danger-text-emphasis);
--bs-form-invalid-border-color: var(--bs-danger);
--bs-form-check-filter: invert(1);
--bs-form-check-input-disabled-color: #333;
--bs-form-color-disabled-filter: brightness(0) invert(1) brightness(0.8);
--bs-form-select-indicator: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 7'%3e%3cpath d='M7 7 0 0h14L7 7z'/%3e%3c/svg%3e");
--bs-form-select-disabled-indicator: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 7'%3e%3cpath fill='%23666' d='M7 7 0 0h14L7 7z'/%3e%3c/svg%3e");
--bs-form-switch-square-bg: #000;
--bs-table-active-bg-factor: 0.135;
--bs-table-hover-bg-factor: 0.065;
--bs-table-striped-bg-factor: 0.035;
--bs-breadcrumb-divider-filter: none;
}
Dark mode
These variables are scoped to our built-in dark mode.
[data-bs-theme=dark] {
color-scheme: dark;
--bs-body-color: #fff;
--bs-body-color-rgb: 255, 255, 255;
--bs-body-bg: #141414;
--bs-body-bg-rgb: 20, 20, 20;
--bs-emphasis-color: #fff;
--bs-emphasis-color-rgb: 255, 255, 255;
--bs-secondary-color: #999;
--bs-secondary-color-rgb: 153, 153, 153;
--bs-secondary-bg: #333;
--bs-secondary-bg-rgb: 51, 51, 51;
--bs-tertiary-color: #666;
--bs-tertiary-color-rgb: 102, 102, 102;
--bs-tertiary-bg: #000;
--bs-tertiary-bg-rgb: 0, 0, 0;
--bs-primary: #ff7900;
--bs-secondary: #fff;
--bs-success: #6c6;
--bs-info: #69f;
--bs-warning: #fc0;
--bs-danger: #f66;
--bs-light: #ccc;
--bs-dark: #000;
--bs-primary-rgb: 255, 121, 0;
--bs-secondary-rgb: 255, 255, 255;
--bs-success-rgb: 102, 204, 102;
--bs-info-rgb: 102, 153, 255;
--bs-warning-rgb: 255, 204, 0;
--bs-danger-rgb: 255, 102, 102;
--bs-light-rgb: 204, 204, 204;
--bs-dark-rgb: 0, 0, 0;
--bs-primary-text-emphasis: #ff7900;
--bs-secondary-text-emphasis: #fff;
--bs-success-text-emphasis: #6c6;
--bs-info-text-emphasis: #69f;
--bs-warning-text-emphasis: #fc0;
--bs-danger-text-emphasis: #f66;
--bs-light-text-emphasis: #ccc;
--bs-dark-text-emphasis: #000;
--bs-primary-bg-subtle: #ff7900;
--bs-secondary-bg-subtle: #fff;
--bs-success-bg-subtle: #6c6;
--bs-info-bg-subtle: #69f;
--bs-warning-bg-subtle: #fc0;
--bs-danger-bg-subtle: #f66;
--bs-light-bg-subtle: #ccc;
--bs-dark-bg-subtle: #000;
--bs-primary-border-subtle: #ff7900;
--bs-secondary-border-subtle: #fff;
--bs-success-border-subtle: #6c6;
--bs-info-border-subtle: #69f;
--bs-warning-border-subtle: #fc0;
--bs-danger-border-subtle: #f66;
--bs-light-border-subtle: #ccc;
--bs-dark-border-subtle: #000;
--bs-success-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 125 125'%3e%3cpath fill='%236c6' 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");
--bs-error-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 125'%3e%3cpath fill='%23f66' 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-heading-color: inherit;
--bs-link-color: #fff;
--bs-link-hover-color: #ff7900;
--bs-link-color-rgb: 255, 255, 255;
--bs-link-hover-color-rgb: 255, 121, 0;
--bs-code-color: #999;
--bs-highlight-color: #000;
--bs-highlight-bg: #fff;
--bs-disabled-color: var(--bs-tertiary-color);
--bs-tertiary-active-bg: #666;
--bs-border-color: #fff;
--bs-border-color-subtle: #666;
--bs-border-color-translucent: rgba(255, 255, 255, 0.15);
--bs-focus-visible-inner-color: #000;
--bs-focus-visible-outer-color: #fff;
--bs-focus-ring-color: rgba(255, 121, 0, 0.25);
--bs-form-valid-color: var(--bs-success-text-emphasis);
--bs-form-valid-border-color: var(--bs-success);
--bs-form-invalid-color: var(--bs-danger-text-emphasis);
--bs-form-invalid-border-color: var(--bs-danger);
--bs-form-check-filter: none;
--bs-form-check-input-disabled-color: #666;
--bs-form-select-indicator: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 7'%3e%3cpath fill='%23fff' d='M7 7 0 0h14L7 7z'/%3e%3c/svg%3e");
--bs-form-select-disabled-indicator: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 7'%3e%3cpath fill='%23999' d='M7 7 0 0h14L7 7z'/%3e%3c/svg%3e");
--bs-form-color-disabled-filter: brightness(0) invert(1) brightness(0.4);
--bs-form-switch-square-bg: #141414;
--bs-table-active-bg-factor: 0.35;
--bs-table-hover-bg-factor: 0.135;
--bs-table-striped-bg-factor: 1;
--bs-breadcrumb-divider-filter: invert(1);
}
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.
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 {
--bs-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(--bs-chevron-icon);
}
.pagination-item:first-child .page-link::before {
background-image: var(--bs-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);
}
Focus variables
Added in v5.3.0
Boosted provides custom :focus
styles using a combination of Sass and CSS variables that can be optionally added to specific components and elements. We do not yet globally override all :focus
styles.
In our Sass, we set default values that can be customized before compiling.
$focus-ring-width: .25rem;
$focus-ring-opacity: .25;
$focus-ring-color: rgba($primary, $focus-ring-opacity);
// Boosted mod: no `$focus-ring-blur`
$focus-ring-box-shadow: null; // Boosted mod: instead of `0 0 $focus-ring-blur $focus-ring-width $focus-ring-color`
Those variables are then reassigned to :root
level CSS variables that can be customized in real-time, including with options for x
and y
offsets (which default to their fallback value of 0
).
--#{$prefix}focus-ring-width: #{$focus-ring-width};
--#{$prefix}focus-ring-opacity: #{$focus-ring-opacity};
--#{$prefix}focus-ring-color: #{$focus-ring-color};
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.