CHAPTER 05
Beginner
Colors, Backgrounds, and Borders
Updated: May 18, 2026
5 min read
# CHAPTER 5
Colors, Backgrounds, and Borders
1. Chapter Introduction
Bootstrap's theme color system provides a consistent palette of semantically named colors — primary, secondary, success, danger, warning, info — that can be applied to backgrounds, text, borders, buttons, and badges with one class. This chapter covers all color utilities and visual styling tools.2. Learning Objectives
- Apply Bootstrap's 8 theme colors to any element.
- Use background color utilities.
- Apply border utilities (color, width, radius).
- Add box shadows.
- Control opacity.
3. Theme Colors
Bootstrap's 8 semantic colors map to a purpose:
text
4. Background Colors
html
5. Gradient Backgrounds
html
6. Border Utilities
html
7. Border Radius (Rounded Corners)
html
8. Shadows
html
9. Opacity
html
10. Common Mistakes
-
Using
bg-warningwith white text: Warning is yellow — white text is hard to read. Usetext-darkwith warning backgrounds.
-
Combining
opacity-25with important content: Low opacity makes text hard to read. Use opacity only for decorative elements.
11. MCQs
Question 1
What class adds a green background?
Question 2
Which color is semantic for errors?
Question 3
What class creates a pill-shaped border radius?
Question 4
What class adds a large shadow?
Question 5
What class adds a border on all sides?
Question 6
border border-primary border-opacity-50 means?
Question 7
What class creates a circular element?
Question 8
What class reduces an entire element's opacity to 50%?
Question 9
What class adds a gradient effect to a background?
Question 10
What text color should you use with bg-warning?
12. Interview Questions
- Q: What are Bootstrap's semantic theme colors? Why are they semantic?
- Q: How do you add a 50% opacity border in Bootstrap 5?
13. Summary
Bootstrap's color system provides semantic, consistent styling through utility classes. Backgrounds, borders, shadows, and opacity can all be controlled without custom CSS. The subtle tints (bg-danger-subtle) added in Bootstrap 5.3 provide elegant light versions of theme colors for modern card designs.