Bootstrap offers a set of color classes for text and backgrounds.
The color system includes primary, secondary, success, danger, warning, info, light, dark, and white.
Colors can be applied using utility classes like .text-*
and .bg-*
.
Bootstrap provides predefined text color classes to change the color of the text.
π Example: Applying Text Colors
<p class="text-primary">This is a primary text.</p>
<p class="text-secondary">This is a secondary text.</p>
<p class="text-success">This is a success text.</p>
<p class="text-danger">This is a danger text.</p>
<p class="text-warning">This is a warning text.</p>
<p class="text-info">This is an info text.</p>
<p class="text-light bg-dark">This is a light text on a dark background.</p>
<p class="text-dark">This is a dark text.</p>
β Explanation:
.text-primary
applies the primary theme color.
.text-danger
applies a red color, typically for errors.
.text-light
is used with dark backgrounds for better contrast.
Bootstrap allows you to apply background colors using the .bg-*
classes.
π Example: Applying Background Colors
<div class="bg-primary text-white p-3">Primary Background</div>
<div class="bg-secondary text-white p-3">Secondary Background</div>
<div class="bg-success text-white p-3">Success Background</div>
<div class="bg-danger text-white p-3">Danger Background</div>
<div class="bg-warning text-dark p-3">Warning Background</div>
<div class="bg-info text-white p-3">Info Background</div>
<div class="bg-light text-dark p-3">Light Background</div>
<div class="bg-dark text-white p-3">Dark Background</div>
β Explanation:
.bg-primary
gives a blue background.
.bg-success
applies a green background for success messages.
.bg-warning
provides a yellow background for warnings.
.text-white
ensures better visibility on dark backgrounds.
Bootstrap offers .bg-opacity-*
classes to adjust background transparency.
π Example: Background Opacity
<div class="bg-primary bg-opacity-25 p-3">25% Opacity</div>
<div class="bg-primary bg-opacity-50 p-3">50% Opacity</div>
<div class="bg-primary bg-opacity-75 p-3">75% Opacity</div>
<div class="bg-primary bg-opacity-100 p-3">100% Opacity</div>
β Explanation:
.bg-opacity-25
makes the background 25% transparent.
.bg-opacity-100
keeps the background fully visible.
If you are using Sass, you can customize Bootstrap colors.
π Example: Customizing Colors in Bootstrap (Sass)
$primary: #ff5733; // Custom primary color
$success: #28a745; // Custom success color
@import "bootstrap";
Bootstrap also provides gradient versions of background colors using .bg-gradient
.
π Example: Gradient Backgrounds
<div class="bg-primary bg-gradient text-white p-3">Primary Gradient</div>
<div class="bg-success bg-gradient text-white p-3">Success Gradient</div>
<div class="bg-danger bg-gradient text-white p-3">Danger Gradient</div>
Bootstrap’s color and background utilities make it easy to design visually appealing web pages. By using predefined classes like .text-*
, .bg-*
, and .bg-opacity-*
, you can quickly style your content without writing additional CSS. π¨β¨
Let me know if you need further explanation! ππ