CSS variables
Use Boosted Innovation Cup’s CSS custom properties for fast and forward-looking design and development.
Boosted Innovation Cup 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 Innovation Cup’s CSS is loaded. They’re located in our _root.scss
file and included in our compiled dist files.
:root {
--bs-blue: #4170d8;
--bs-indigo: #b181d8;
--bs-purple: #b181d8;
--bs-pink: #ffabd4;
--bs-red: #ff2828;
--bs-orange: #5093ff;
--bs-yellow: #fc0;
--bs-green: #3baa3c;
--bs-teal: #4fc887;
--bs-cyan: #71c2f6;
--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: #5093ff;
--bs-secondary: #000;
--bs-success: #3baa3c;
--bs-info: #4170d8;
--bs-warning: #fc0;
--bs-danger: #ff2828;
--bs-light: #ccc;
--bs-dark: #000;
--bs-primary-rgb: 80, 147, 255;
--bs-secondary-rgb: 0, 0, 0;
--bs-success-rgb: 59, 170, 60;
--bs-info-rgb: 65, 112, 216;
--bs-warning-rgb: 255, 204, 0;
--bs-danger-rgb: 255, 40, 40;
--bs-light-rgb: 204, 204, 204;
--bs-dark-rgb: 0, 0, 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 16 16' fill='currentColor'%3e%3cpath d='M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z'/%3e%3c/svg%3e");
--o-close-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
--o-check-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425a.247.247 0 0 1 .02-.022Z'/%3e%3c/svg%3e");
--o-success-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%233baa3c'%3e%3cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z'/%3e%3c/svg%3e");
--o-error-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ff2828'%3e%3cpath d='M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z'/%3e%3c/svg%3e");
--bs-font-sans-serif: "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: #1976d2;
--bs-code-color: #666;
--bs-highlight-color: #fff;
--bs-highlight-bg: #000;
}
Component variables
Boosted Innovation Cup is 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. 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),
[class*="bg-secondary"] {
--#{$prefix}link-color: #{$link-color-dark};
--#{$prefix}link-hover-color: #{$link-hover-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}link-color: #{$link-color};
--#{$prefix}link-hover-color: #{$link-hover-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 Innovation Cup 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.