Bootstrap 5 Colors
Bootstrap has a small set of theme colours with meaningful names. Learn these eight names once and you can use them on text, backgrounds, borders, buttons, alerts, badges and almost every other component.
| Name | Typical meaning |
|---|---|
primary |
Main brand / action colour (blue) |
secondary |
Less important (grey) |
success |
Something went well (green) |
danger |
Error or destructive action (red) |
warning |
Needs attention (yellow) |
info |
Neutral information (cyan) |
light |
Very light grey |
dark |
Near black |
Text colours
<!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/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<p class="text-primary mb-1">.text-primary</p>
<p class="text-secondary mb-1">.text-secondary</p>
<p class="text-success mb-1">.text-success</p>
<p class="text-danger mb-1">.text-danger</p>
<p class="text-warning mb-1">.text-warning</p>
<p class="text-info mb-1">.text-info</p>
<p class="text-body-secondary mb-1">.text-body-secondary (muted)</p>
<p class="text-dark bg-light mb-1">.text-dark on .bg-light</p>
<p class="text-white bg-dark mb-1">.text-white on .bg-dark</p>
<p class="text-primary-emphasis mb-0">.text-primary-emphasis (darker, readable shade)</p>
</body>
</html>Note:
.text-mutedfrom older versions still works, but Bootstrap 5.3 recommends.text-body-secondary, which adapts to dark mode.
Background colours
.bg-* sets the background. It does not change the text colour, so pair it with a text class — or use .text-bg-*, which sets a background and a readable contrasting text colour in one go.
<!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/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="row g-2">
<div class="col-4"><div class="p-2 text-bg-primary">primary</div></div>
<div class="col-4"><div class="p-2 text-bg-success">success</div></div>
<div class="col-4"><div class="p-2 text-bg-danger">danger</div></div>
<div class="col-4"><div class="p-2 text-bg-warning">warning</div></div>
<div class="col-4"><div class="p-2 text-bg-info">info</div></div>
<div class="col-4"><div class="p-2 text-bg-dark">dark</div></div>
<div class="col-4"><div class="p-2 bg-primary-subtle text-primary-emphasis border border-primary-subtle">subtle</div></div>
<div class="col-4"><div class="p-2 bg-success bg-gradient text-white">gradient</div></div>
<div class="col-4"><div class="p-2 bg-danger bg-opacity-25">opacity 25</div></div>
</div>
</body>
</html>Colour class reference
| Class | Effect |
|---|---|
.text-{color} |
Text colour |
.bg-{color} |
Background colour only |
.text-bg-{color} |
Background + contrasting text colour |
.bg-{color}-subtle |
Pale tint of the colour (5.3) |
.text-{color}-emphasis |
Dark, high-contrast shade for text on subtle backgrounds (5.3) |
.border-{color} / .border-{color}-subtle |
Border colour |
.bg-gradient |
Adds a subtle gradient overlay |
.bg-opacity-{10,25,50,75} / .text-opacity-* |
Transparency |
.bg-body, .bg-body-secondary, .bg-body-tertiary |
Page-background shades that follow dark mode |
.link-{color} |
Coloured links with matching hover state |
CSS variables
In Bootstrap 5.3 every colour is also a CSS custom property on :root, e.g. --bs-primary and --bs-primary-rgb. Utilities read those variables, so you can re-theme a section by overriding them, or use them in your own CSS.
<!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/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.my-box { border-left: 6px solid var(--bs-success); background: var(--bs-success-bg-subtle); }
.purple { --bs-link-color-rgb: 121, 82, 179; }
</style>
</head>
<body class="p-3">
<div class="my-box p-3 mb-3">My own class, using Bootstrap's colour variables.</div>
<p><a href="#">Normal link</a> · <span class="purple"><a href="#">Re-coloured link</a></span></p>
<script>
const css = getComputedStyle(document.documentElement);
console.log('--bs-primary =', css.getPropertyValue('--bs-primary').trim());
</script>
</body>
</html>Tip: Colour alone doesn't carry meaning for colour-blind users or screen readers. If a red box means "error", also say so in the text (or with
visually-hiddentext).
Test yourself
Which class sets a green background AND a readable text colour?
- .bg-success
- .text-success
- .text-bg-success
- .bg-green
Which theme colour name is conventionally used for errors?
- warning
- danger
- dark
- secondary
What does .bg-primary-subtle give you?
- A darker primary
- A pale tint of the primary colour
- A primary-coloured border
- Transparent background