Skip to main content

Utilities

Opacity

Control the opacity of elements.

How it works

The opacity property sets the opacity level for an element. The opacity level describes the transparency level, where 1 is not transparent at all, .5 is 50% visible, and 0 is completely transparent.

Set the opacity of an element using .opacity-{value} utilities.

100%
75%
50%
25%
0%
HTML
<div class="opacity-100 p-3 text-bg-primary fw-bold rounded">100%</div>
<div class="opacity-75 p-3 text-bg-primary fw-bold rounded">75%</div>
<div class="opacity-50 p-3 text-bg-primary fw-bold rounded">50%</div>
<div class="opacity-25 p-3 text-bg-primary fw-bold rounded">25%</div>
<div class="opacity-0 p-3 text-bg-primary fw-bold rounded">0%</div>
Classopacity
.opacity-00
.opacity-250.25
.opacity-500.5
.opacity-750.75
.opacity-1001

Whole element vs. color only

These classes fade everything inside the element — text, border and children alike. If you only want a lighter background or lighter text, keep the element opaque and use the color-channel utilities instead:

  • .bg-opacity-* on a .bg-{color} — see Background.
  • .text-opacity-* on a .text-{color} — see Colors.
  • .border-opacity-* on a .border-{color} — see Borders.
  • .link-opacity-* on a link — see Link.
opacity-50 — text fades too
bg-opacity-50 — text stays solid
HTML
<div class="opacity-50 p-3 text-bg-navy rounded">opacity-50 — text fades too</div>
<div class="bg-navy bg-opacity-50 p-3 rounded">bg-opacity-50 — text stays solid</div>

Accessibility

An element at .opacity-0 is still in the page: it keeps its space, it can be focused, and screen readers announce it. Use .opacity-0 only for things that are about to animate in. For a hidden element use .d-none; for a reserved blank space use .invisible. Text under .opacity-50 rarely passes 4.5:1 contrast on the cream background — check it before you ship.

CSS

"opacity": (
  property: opacity,
  values: (
    0: 0,
    25: .25,
    50: .5,
    75: .75,
    100: 1,
  )
),