Prior to Bootstrap 5, theming required compiling Sass with Node.js build tools. Bootstrap 5 revolutionized frontend theming by exposing hundreds of Native CSS Custom Properties (CSS Variables) prefixed with --bs-*. This allows developers to inspect, modify, and animate design tokens in real time directly in the browser using plain CSS or JavaScript!
Bootstrap organizes CSS custom properties into two distinct levels:
1. Root Variables (:root): Global tokens including colors (--bs-primary, --bs-primary-rgb), font families, body backgrounds, and breakpoint values.
2. Component-Scoped Variables: Scoped directly to individual components (such as --bs-card-bg, --bs-btn-padding-y, --bs-modal-width), allowing local overrides without affecting global styles.
Customize a single card's background, border, and padding without writing new CSS class selectors:
<!-- Card customized entirely via inline CSS custom properties -->
<div class="card shadow-sm" style="--bs-card-bg: #faf8fc; --bs-card-border-color: #332246; --bs-card-spacer-y: 2rem;">
<div class="card-body">
<h4 class="card-title text-primary">Custom Token Card</h4>
<p class="card-text">Locally scoped variables override Bootstrap defaults for this container only!</p>
</div>
</div>
Allow users to select a custom brand accent color using an HTML5 color picker:
<label for="colorPicker" class="form-label">Pick Custom Theme Color:</label>
<input type="color" class="form-control form-control-color" id="colorPicker" value="#332246">
<script>
const picker = document.getElementById('colorPicker');
picker.addEventListener('input', (e) => {
// Dynamically update root primary theme color across entire webpage
document.documentElement.style.setProperty('--bs-primary', e.target.value);
});
</script>
Strengthen your responsive web design mastery by studying these connected classes:
Understand how Sass variables compile down into native CSS variables.
Leverage root CSS variables to toggle light and dark color schemes.
Use --bs-primary-rgb and rgba() for custom transparent color tints.
Update CSS variables dynamically at runtime using document.documentElement.
13, 110, 253), enabling Bootstrap to create transparent colors: rgba(var(--bs-primary-rgb), 0.5).
@media query width definitions.
Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.
Continue to Class 41: Utility API in Sass → Previous: ← Class 39: Sass Customization | Full Syllabus