Class 9 of 48 • Content & Typography

Bootstrap 5 Color Palette, Backgrounds & Color Modes

Bootstrap 5 includes an extensive, semantic color palette designed to convey meaning, state, and brand identity across all UI elements. With the release of Bootstrap 5.3+, the color system was completely overhauled with Subtle Color Variants (e.g. .bg-primary-subtle) and CSS Variable Color Modes that automatically adjust their contrast between light and dark themes.

Bootstrap 5 Semantic Theme Colors and Text/Background Utilities
Figure 9: The core theme color spectrum (Primary, Secondary, Success, Danger, Warning, Info, Light, Dark) with contrast ratios.

1. The 9 Core Theme Colors

Bootstrap provides 9 semantic colors that express intent consistently across buttons, alerts, badges, and text:

Primary (#0d6efd)
Main Brand Actions
Secondary (#6c757d)
Muted / Secondary
Success (#198754)
Success / Positive
Danger (#dc3545)
Errors / Critical
Warning (#ffc107)
Caution / Alerts
Info (#0dcaf0)
Tips / Informative

2. Modern Subtle Backgrounds & Text Colors (Bootstrap 5.3+)

In earlier Bootstrap versions, using saturated backgrounds like .bg-primary for alert boxes often caused jarring visual contrast. Modern Bootstrap introduces subtle background classes (.bg-*-subtle) paired with matching text emphasis classes (.text-*-emphasis):

<!-- Soft, modern alert style cards with subtle backgrounds -->
<div class="p-3 mb-2 bg-primary-subtle text-primary-emphasis rounded border border-primary-subtle">
  <strong>Primary Notice:</strong> Soft blue background with high-contrast text.
</div>

<div class="p-3 mb-2 bg-success-subtle text-success-emphasis rounded border border-success-subtle">
  <strong>Success Notice:</strong> Gentle green tint for confirmation messages.
</div>

<div class="p-3 mb-2 bg-warning-subtle text-warning-emphasis rounded border border-warning-subtle">
  <strong>Warning Notice:</strong> Subtle amber tone for cautious guidance.
</div>

<div class="p-3 mb-2 bg-danger-subtle text-danger-emphasis rounded border border-danger-subtle">
  <strong>Danger Notice:</strong> Light rose tint for error explanations.
</div>

3. Text Opacity & Background Opacity Utilities

Bootstrap 5 provides alpha opacity utilities without requiring custom hex alpha codes or rgba declarations. Simply chain .text-opacity-* or .bg-opacity-* (values: 25, 50, 75, 100):

<!-- Text Opacity Examples -->
<div class="text-primary text-opacity-100">100% Opacity Primary Text</div>
<div class="text-primary text-opacity-75">75% Opacity Primary Text</div>
<div class="text-primary text-opacity-50">50% Opacity Primary Text</div>
<div class="text-primary text-opacity-25">25% Opacity Primary Text</div>

<!-- Background Opacity with text-bg-dark helper -->
<div class="bg-dark bg-opacity-50 text-white p-3 rounded">
  50% Transparent Dark Overlay Background
</div>

BCA University Exam Viva Tip

Q: What is the purpose of the .text-bg-* helper in Bootstrap 5?
Ans: The .text-bg-* class (e.g. .text-bg-primary, .text-bg-dark) sets both the background color AND an accessible, high-contrast text color simultaneously, ensuring compliance with WCAG color contrast guidelines.

Explore Related Bootstrap Tutorials & Next Steps

Strengthen your responsive web design mastery by studying these connected classes:

Typography & Display Text

Pair contextual colors with headings, lead text, and blockquotes.

Dark Mode & Color Modes

Explore how theme colors adapt dynamically between light and dark modes.

CSS Custom Properties (--bs-*)

Dynamically customize color variables at runtime with JavaScript.

Customizing $theme-colors Map

Add custom corporate brand colors directly into the Sass color map.

Frequently Asked Questions (FAQ) - Student & Interview Review

Subtle backgrounds (.bg-*-subtle) use CSS custom properties. In light mode, they render as light pastel tints; in dark mode (data-bs-theme='dark'), they automatically transform into deep, dark shades with light text!
Yes! Using Sass, you can merge custom colors into the $theme-colors map (e.g. $theme-colors: ('brand': #7952b3);). The compiler will automatically generate .text-brand, .bg-brand, and .btn-brand.
In Bootstrap 5.3+, .text-muted has been deprecated in favor of .text-body-secondary. Secondary text utilizes native CSS variables that adapt seamlessly to light and dark themes.

Next Step in Your Bootstrap Learning Path:

Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.

Continue to Class 10: Tables & Responsive Styles → Previous: ← Class 8: Typography & Headings | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!