Color utilities help you quickly change text and background colors without writing custom CSS. They make your website look nice and clear.
Color utilities (text, background) in Bootsrap
text-{color}
bg-{color}Replace {color} with Bootstrap color names like primary, success, danger, warning, info, light, dark, or white.
Use text- classes to change text color and bg- classes to change background color.
<p class="text-primary">This text is blue.</p>
<div class="bg-success text-white p-3">Green background with white text.</div>
<span class="text-danger">Warning message in red.</span>
<section class="bg-light text-dark p-4">Light background with dark text.</section>
This example shows different Bootstrap color utility classes applied to text and backgrounds. It uses text-primary for blue text, text-success for green text, bg-warning for a yellow background, bg-danger for a red button background, and bg-info for a light blue section background with white text. Padding and margin classes add spacing.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Color Utilities Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container my-5"> <h1 class="text-primary">Hello, Bootstrap Colors!</h1> <p class="text-success">This text is green to show success.</p> <div class="bg-warning text-dark p-3 mb-3">Warning background with dark text.</div> <button class="btn bg-danger text-white">Danger Button</button> <section class="bg-info text-white p-4 mt-4 rounded"> <p>This section has an info background and white text.</p> </section> </main> </body> </html>
Bootstrap color utilities are responsive and accessible by default.
Use padding (p-*) and margin (m-*) classes to add space around colored elements.
For better accessibility, ensure sufficient contrast between text and background colors.
Use text-{color} to change text color quickly.
Use bg-{color} to change background color easily.
Bootstrap provides many color options to keep your design consistent and simple.