← Back to Bootstrap Course | Chapter 4: Colors & Spacing | Lesson 2 of 7

Text colors

Text colour utilities colour text and pair well with background utilities for accessible contrast.

In this page:

  1. Text colors
Syntax
markup
<p class="text-primary">text</p>
<p class="text-danger-emphasis">text</p>
<p class="text-body-secondary">text</p>

Text colors

The same theme colours are available as text-* classes, with -emphasis variants for stronger contrast and text-body-* for neutral shades. Use text-white or text-dark to fix contrast on coloured backgrounds. text-opacity-* softens the colour.

Note: Check contrast; text-warning on white is hard to read.

Example: Text colors

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <p class="text-primary">text-primary</p>
  <p class="text-danger-emphasis">text-danger-emphasis</p>
  <div class="bg-dark p-2"><span class="text-white">white on dark</span> <span class="text-white text-opacity-50">50% opacity</span></div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Low contrast such as yellow on white
  2. Using text-muted where dark mode support matters
  3. Mixing many colours
Chapter Summary
  • text-{theme} colours text
  • -emphasis variants add contrast
  • text-white and text-dark fix contrast
  • text-opacity softens text
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.