Bootstrap 5 Tutorial
v5.3.0Bootstrap 5 Tutorial
Colors & Backgrounds in Bootstrap 5
Theme Colors
Bootstrap includes a set of predefined theme colors that convey meaning across your application.
Theme Color Palette
<!-- Background colors -->
<div class="bg-primary text-white">Primary background</div>
<div class="bg-success text-white">Success background</div>
<div class="bg-warning text-dark">Warning background</div>
<div class="bg-light text-dark">Light background</div>
<!-- Text colors -->
<p class="text-primary">Primary text</p>
<p class="text-success">Success text</p>
<p class="text-warning">Warning text</p>
<p class="text-muted">Muted text</p>Color Utilities
Text Colors
.text-primary - Primary text color
.text-secondary - Secondary text color
.text-success - Success text color
.text-danger - Danger text color
.text-warning - Warning text color
.text-info - Info text color
.text-light - Light text color
.text-dark - Dark text color
.text-muted - Muted text color
.text-white - White text color
.text-body - Default body color
.text-black-50 - Black with 50% opacity
.text-white-50 - White with 50% opacity
Background Colors
Color Usage Examples
Buttons
Alerts
Badges
Customizing Theme Colors
SCSS Customization
Customize theme colors in your SCSS variables:
// Custom theme colors
$primary: #3498db;
$secondary: #2ecc71;
$success: #27ae60;
$danger: #e74c3c;
$warning: #f39c12;
$info: #17a2b8;
$light: #f8f9fa;
$dark: #343a40;
// Additional colors
$custom-colors: (
"custom-blue": #007bff,
"custom-indigo": #6610f2,
"custom-purple": #6f42c1,
"custom-pink": #e83e8c,
"custom-red": #dc3545,
"custom-orange": #fd7e14,
"custom-yellow": #ffc107,
"custom-green": #28a745,
"custom-teal": #20c997,
"custom-cyan": #17a2b8
);
// Merge with default theme colors
$theme-colors: map-merge($theme-colors, $custom-colors);
// Import Bootstrap
@import "bootstrap/scss/bootstrap";Best Practices
Color Usage Guidelines
- Consistency: Use the same colors for the same actions throughout your application
- Accessibility: Ensure sufficient contrast ratio between text and background
- Semantic meaning: Use colors that convey appropriate meaning (green for success, red for errors)
- Moderation: Don't use too many different colors on one page
- Responsive: Test colors on different devices and lighting conditions
Explore Related Tools
Hand-picked utilities and calculators related to this tool.
