Custom component variants let you change how Bootstrap parts look to fit your style. It helps your website feel unique and match your brand.
You want buttons with your brand colors instead of default Bootstrap colors.
You need alerts that look different for special messages.
You want cards with a unique background or border style.
You want to reuse a style easily across many components.
You want to keep Bootstrap but add your own style twist.
Syntax
Bootsrap
/* Define a new color variant using CSS custom properties */
.btn-custom {
--bs-btn-bg: #4a90e2;
--bs-btn-color: white;
--bs-btn-border-color: #4a90e2;
}
<!-- Use the new variant class on a button -->
<button class="btn btn-custom">Custom Button</button>
You create a new class that changes Bootstrap CSS variables.
Apply your new class along with Bootstrap's base class like btn.
Examples
This example makes a green button variant using Bootstrap variables.
What is the most likely reason your custom variant btn-special is not working?
medium
A. You need to import Bootstrap JavaScript for styles to work
B. You used the wrong color code format
C. You forgot to add the custom class btn-special to the button element
D. You must use !important in SCSS to override styles
Solution
Step 1: Check SCSS usage
The SCSS defines styles for the btn-special class but does not apply it automatically.
Step 2: Confirm HTML class usage
To see the style, the button element must have class btn-special along with btn.
Final Answer:
You forgot to add the custom class btn-special to the button element -> Option C
Quick Check:
Custom class must be on element to apply styles [OK]
Hint: Add your custom class to HTML element to see styles [OK]
Common Mistakes:
Assuming SCSS applies styles without HTML class
Thinking JavaScript is needed for CSS styles
Using !important unnecessarily
5. You want to create a custom Bootstrap card variant with a blue border and light blue background. Which SCSS code correctly creates a card-blue variant and applies it to a card?