Bootstrap Colors

Text, background and theme colours.

✍️ 3 exercises + code challenge in this lesson

Bootstrap has theme colours: primary, secondary, success, danger, warning, info, light, dark.

  • Text: .text-success
  • Background: .bg-danger, softer .bg-danger-subtle
  • .text-bg-warning sets a background with a matching readable text colour.

Key Takeaways: Bootstrap Colors

Mastering Bootstrap Colors helps you write clean and reliable Bootstrap code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Bootstrap Colors Code Example

Bootstrap
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container py-3">
  <p class="text-primary">.text-primary</p>
  <p class="text-success">.text-success</p>
  <p class="text-danger">.text-danger</p>
  <div class="p-2 mb-2 text-bg-primary">.text-bg-primary</div>
  <div class="p-2 mb-2 text-bg-warning">.text-bg-warning</div>
  <div class="p-2 mb-2 bg-success-subtle border border-success">.bg-success-subtle</div>
  <div class="p-2 text-bg-dark">.text-bg-dark</div>
</div>
Free sign-in required · Google login available

Bootstrap Colors Practice Exercises

Check what you learned in “Bootstrap Colors”.

/ 3 solved
Fill in the blank

Make the text red (danger colour).

<p class="">Error!</p>
✓ Correct! Not quite. Try again.
Multiple choice

Which class sets a background AND a readable text colour?

✓ Correct! Not quite. Try again.
Code challenge

Give the div a warning background with readable text using "text-bg-warning".

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services