Background
Background utilities paint an element with a theme colour, a subtle tint, the body surface or a gradient. Combine bg-{colour} with bg-opacity-* or the --ui-bg-opacity variable to fade it, and prefer the text-bg-* helpers or -emphasis text colours so contrast stays readable in light and dark mode.
1Theme colour backgrounds
bg-primary to bg-dark fill an element with a theme colour. Pair them with a readable text colour.
<div class="row g-2 small">
<div class="col-6 col-md-3">
<div class="bg-primary text-white rounded-md p-4">
bg-primary
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-secondary text-white rounded-md p-4">
bg-secondary
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-success text-white rounded-md p-4">
bg-success
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-danger text-white rounded-md p-4">
bg-danger
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-warning text-dark rounded-md p-4">
bg-warning
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-info text-dark rounded-md p-4">
bg-info
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-light text-dark rounded-md p-4 border">
bg-light
</div>
</div>
<div class="col-6 col-md-3">
<div class="bg-dark text-white rounded-md p-4">
bg-dark
</div>
</div>
</div>2Subtle backgrounds
The -subtle variants are soft tints that work in light and dark mode; use the matching -emphasis text colour.
<div class="grid gap-2">
<div class="bg-primary-subtle text-primary-emphasis rounded-lg px-4 py-2">
bg-primary-subtle
</div>
<div class="bg-success-subtle text-success-emphasis rounded-lg px-4 py-2">
bg-success-subtle
</div>
<div class="bg-warning-subtle text-warning-emphasis rounded-lg px-4 py-2">
bg-warning-subtle
</div>
<div class="bg-danger-subtle text-danger-emphasis rounded-lg px-4 py-2">
bg-danger-subtle
</div>
<div class="bg-info-subtle text-info-emphasis rounded-lg px-4 py-2">
bg-info-subtle
</div>
</div>3Body backgrounds
bg-body, bg-body-secondary and bg-body-tertiary follow the page surface and adapt to colour mode.
bg-body - the page itselfbg-body-secondary - side panelsbg-body-tertiary - wells and inputs<div class="border rounded-xl overflow-hidden">
<div class="bg-page p-4 border-b">
<code>bg-body</code> - the page itself
</div>
<div class="bg-surface-2 p-4 border-b">
<code>bg-body-secondary</code> - side panels
</div>
<div class="bg-surface-3 p-4">
<code>bg-body-tertiary</code> - wells and inputs
</div>
</div>4Text and background together
text-bg-{colour} sets the background and a contrasting text colour in one class.
<div class="flex flex-wrap gap-2">
<span class="text-bg-primary rounded-full px-4 py-1">text-bg-primary</span> <span class="text-bg-warning rounded-full px-4 py-1">text-bg-warning</span> <span class="text-bg-info rounded-full px-4 py-1">text-bg-info</span> <span class="text-bg-light rounded-full px-4 py-1 border">text-bg-light</span> <span class="text-bg-dark rounded-full px-4 py-1">text-bg-dark</span>
</div>5Background opacity steps
bg-opacity-10, -25, -50, -75 and -100 fade a theme background in fixed steps.
<div class="flex flex-wrap gap-2">
<div class="bg-success/100 text-white rounded-lg p-4 small">
100
</div>
<div class="bg-success/75 text-white rounded-lg p-4 small">
75
</div>
<div class="bg-success/50 rounded-lg p-4 small">
50
</div>
<div class="bg-success/25 rounded-lg p-4 small">
25
</div>
<div class="bg-success/10 rounded-lg p-4 small">
10
</div>
</div>6Gradient overlay
bg-gradient adds a soft white-to-transparent gradient on top of any bg-{colour}.
<div class="row g-2">
<div class="col-sm-6">
<div class="bg-primary bg-gradient text-white rounded-xl p-6">
<div class="font-semibold">
bg-primary bg-gradient
</div>
<div class="small text-white/50">
Same-day appointments
</div>
</div>
</div>
<div class="col-sm-6">
<div class="bg-dark bg-gradient text-white rounded-xl p-6">
<div class="font-semibold">
bg-dark bg-gradient
</div>
<div class="small text-white/50">
Online results
</div>
</div>
</div>
</div>7Transparent background
bg-transparent removes a fill, useful when a component's default background must disappear.
<div class="bg-surface-3 rounded-lg p-4 flex flex-wrap gap-2">
<div class="bg-white border rounded-md px-4 py-2 small">
bg-white
</div>
<div class="bg-transparent border rounded-md px-4 py-2 small">
bg-transparent
</div>
<button type="button" class="btn btn-light bg-transparent border-0"><i class="bi bi-three-dots" aria-hidden="true"></i> Ghost button</button>
</div>8Black and white
bg-black and bg-white are fixed colours that do not change with colour mode, unlike bg-body.
<div class="flex rounded-lg overflow-hidden border">
<div class="bg-black text-white flex-auto p-4 text-center small">
bg-black
</div>
<div class="bg-white text-black flex-auto p-4 text-center small">
bg-white
</div>
</div>9Highlighted table row
Background utilities on a table cell or row mark a selection without extra CSS.
| Order | Customer | Total |
|---|---|---|
| #TX-6430 | Noah Hughes | $178.99 |
| #ORD-8148 | Leo Ibrahim | $367.79 |
| #TX-2018 | Diego Ibrahim | $370.39 |
<div class="table-responsive">
<table class="table table-sm mb-0 align-middle">
<thead>
<tr>
<th scope="col">Order</th>
<th scope="col">Customer</th>
<th scope="col" class="text-end">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>#TX-6430</td>
<td>Noah Hughes</td>
<td class="text-end">$178.99</td>
</tr>
<tr>
<td class="bg-primary-subtle">#ORD-8148</td>
<td class="bg-primary-subtle">Leo Ibrahim</td>
<td class="bg-primary-subtle text-end font-semibold">$367.79</td>
</tr>
<tr>
<td>#TX-2018</td>
<td>Diego Ibrahim</td>
<td class="text-end">$370.39</td>
</tr>
</tbody>
</table>
</div>10Feature icons on tinted circles
A subtle background with rounded-circle and fixed size gives each icon a soft colour badge.
<div class="row g-3">
<div class="col-sm-4 flex gap-2 items-center">
<span class="bg-primary-subtle text-primary rounded-full inline-flex items-center justify-center text-lg" style="width:44px;height:44px"><i class="bi bi-lightning-charge-fill" aria-hidden="true"></i></span><span class="small font-medium">Certified specialists</span>
</div>
<div class="col-sm-4 flex gap-2 items-center">
<span class="bg-success-subtle text-success rounded-full inline-flex items-center justify-center text-lg" style="width:44px;height:44px"><i class="bi bi-shield-check" aria-hidden="true"></i></span><span class="small font-medium">Same-day appointments</span>
</div>
<div class="col-sm-4 flex gap-2 items-center">
<span class="bg-danger-subtle text-danger rounded-full inline-flex items-center justify-center text-lg" style="width:44px;height:44px"><i class="bi bi-heart-fill" aria-hidden="true"></i></span><span class="small font-medium">Insurance friendly</span>
</div>
</div>11Section bands
Alternating bg-body and bg-body-tertiary bands separate page sections.
Care that puts you first
This elegant goal lets the whole team on the same page on any device.
Modern healthcare close to home
Our physiotherapy makes projects moving forward with friendly support.
Feel better with expert care
This elegant idea makes the whole team on the same page from the very first day.
<div class="border rounded-xl overflow-hidden">
<section class="bg-page p-6">
<h3 class="h6 mb-1">Care that puts you first</h3>
<p class="small mb-0 text-muted">This elegant goal lets the whole team on the same page on any device.</p>
</section>
<section class="bg-surface-3 p-6">
<h3 class="h6 mb-1">Modern healthcare close to home</h3>
<p class="small mb-0 text-muted">Our physiotherapy makes projects moving forward with friendly support.</p>
</section>
<section class="bg-page p-6">
<h3 class="h6 mb-1">Feel better with expert care</h3>
<p class="small mb-0 text-muted">This elegant idea makes the whole team on the same page from the very first day.</p>
</section>
</div>12Dark footer strip
bg-dark with text-white-50 and link-light builds a compact footer.
<footer class="bg-dark text-white/50 rounded-lg p-4 flex flex-col sm:flex-row justify-between gap-2 small">
<span>© Brand name 15</span> <span class="flex gap-4"><a href="#" class="link-light">Privacy</a><a href="#" class="link-light">Terms</a><a href="#" class="link-light">Contact</a></span>
</footer>13Alert-like message
A message strip built from bg-danger-subtle, a matching border and emphasis text.
<div class="bg-danger-subtle border border-danger/30 text-danger-emphasis rounded-lg p-4 flex gap-2" role="alert">
<span class="text-lg"><i class="bi bi-exclamation-octagon-fill" aria-hidden="true"></i></span>
<div>
<strong>Payment failed.</strong> <span class="small">The new family plans helps projects moving forward without extra tools.</span>
</div>
</div>14Background on hoverable list
List items with bg-body-tertiary for the active one; other rows stay on bg-body.
- Inbox
- Starred
- Sent
- Archive
<ul class="list-unstyled border rounded-lg mb-0 overflow-hidden" style="max-width:20rem">
<li class="px-4 py-2 bg-page border-b"><i class="bi bi-inbox" aria-hidden="true"></i> Inbox</li>
<li class="px-4 py-2 bg-surface-3 border-b font-semibold"><i class="bi bi-star-fill" aria-hidden="true"></i> Starred</li>
<li class="px-4 py-2 bg-page border-b"><i class="bi bi-send" aria-hidden="true"></i> Sent</li>
<li class="px-4 py-2 bg-page"><i class="bi bi-archive" aria-hidden="true"></i> Archive</li>
</ul>15Progress made from backgrounds
A bg-body-secondary track and a bg-success fill with a width utility form a simple meter.
<div class="grid gap-4">
<div>
<div class="flex justify-between small mb-1">
<span>Storage</span><span>75 of 100 GB</span>
</div>
<div class="bg-surface-2 rounded-full" style="height:8px">
<div class="bg-success rounded-full h-full w-3/4">
</div>
</div>
</div>
<div>
<div class="flex justify-between small mb-1">
<span>Seats</span><span>5 of 20</span>
</div>
<div class="bg-surface-2 rounded-full" style="height:8px">
<div class="bg-warning rounded-full h-full w-1/4">
</div>
</div>
</div>
</div>16Pricing highlight
The recommended plan gets bg-primary and white text; the others stay on bg-body-tertiary.
<div class="row g-2 text-center">
<div class="col-4">
<div class="bg-surface-3 rounded-lg p-4">
<div class="small">
Basic
</div>
<div class="text-lg font-bold">
$6.32
</div>
</div>
</div>
<div class="col-4">
<div class="bg-primary text-white rounded-lg p-4">
<div class="small">
Pro
</div>
<div class="text-lg font-bold">
$31.13
</div>
</div>
</div>
<div class="col-4">
<div class="bg-surface-3 rounded-lg p-4">
<div class="small">
Team
</div>
<div class="text-lg font-bold">
$68.20
</div>
</div>
</div>
</div>17Colour swatches
Square swatches with bg-{colour} and a caption below, as used in a style guide.
<div class="flex flex-wrap gap-4">
<figure class="mb-0 text-center">
<div class="bg-primary rounded-lg" style="width:56px;height:56px">
</div>
<figcaption class="small mt-1">Primary</figcaption>
</figure>
<figure class="mb-0 text-center">
<div class="bg-secondary rounded-lg" style="width:56px;height:56px">
</div>
<figcaption class="small mt-1">Secondary</figcaption>
</figure>
<figure class="mb-0 text-center">
<div class="bg-success rounded-lg" style="width:56px;height:56px">
</div>
<figcaption class="small mt-1">Success</figcaption>
</figure>
<figure class="mb-0 text-center">
<div class="bg-warning rounded-lg" style="width:56px;height:56px">
</div>
<figcaption class="small mt-1">Warning</figcaption>
</figure>
<figure class="mb-0 text-center">
<div class="bg-surface-2 border rounded-lg" style="width:56px;height:56px">
</div>
<figcaption class="small mt-1">Surface</figcaption>
</figure>
</div>18Card header and footer tints
bg-body-tertiary on the header and footer of a card, bg-body in the middle.
<div class="border rounded-lg overflow-hidden" style="max-width:24rem">
<div class="bg-surface-3 px-4 py-2 border-b font-semibold small">
9 lessons from our idea
</div>
<div class="bg-page p-4 small">
A focused plan makes results you can measure all year round.
</div>
<div class="bg-surface-3 px-4 py-2 border-t small text-muted">
Updated just now
</div>
</div>19Image scrim with bg-black
A bg-black layer at reduced --ui-bg-opacity makes white text readable over a photo.
<div class="relative rounded-xl overflow-hidden" style="max-width:28rem">
<img src="../assets/img/wide-5.svg" alt="Modern healthcare close to home" class="w-full block">
<div class="absolute top-0 start-0 w-full h-full bg-black flex items-center justify-center" style="--ui-bg-opacity:.45">
<span class="text-white text-lg font-semibold text-center px-4">Modern healthcare close to home</span>
</div>
</div>20Chat bubbles
Incoming messages on bg-body-tertiary, outgoing on bg-primary, each with a rounded corner set.
<div class="flex flex-col gap-2" style="max-width:24rem">
<div class="self-start bg-surface-3 rounded-xl rounded-b-none px-4 py-2 small">
A elegant community makes customers coming back for teams of every size.
</div>
<div class="self-end bg-primary text-white rounded-xl rounded-b-none px-4 py-2 small">
This powerful project lets you focused on what matters all year round.
</div>
<div class="self-start bg-surface-3 rounded-xl rounded-b-none px-4 py-2 small">
This bright workflow guides your work organised wherever you are.
</div>
</div>