Utilities
Link
Link utilities are used to stylize your anchors to adjust their color, opacity, underline offset, underline color, and more.
How it works
Links in this theme are navy-700 with an underline, and turn gold-800 on hover (gold-500 in dark mode). The
utilities below adjust that look without a custom stylesheet: fade the link, move the underline away from the
text, recolor the underline on its own, or drop it until hover. They work by setting the
--bs-link-opacity and --bs-link-underline-opacity variables that the base link
rule reads. Colored links (.link-primary, .link-gold, …) are on
Colored links.
Link opacity
Change the alpha opacity of the link rgba() color value with utilities. Please be aware that
changes to a color's opacity can lead to links with
insufficient contrast.
HTML
<p><a class="link-opacity-10" href="#link-opacity">Link opacity 10</a></p>
<p><a class="link-opacity-25" href="#link-opacity">Link opacity 25</a></p>
<p><a class="link-opacity-50" href="#link-opacity">Link opacity 50</a></p>
<p><a class="link-opacity-75" href="#link-opacity">Link opacity 75</a></p>
<p><a class="link-opacity-100" href="#link-opacity">Link opacity 100</a></p>You can even change the opacity level on hover.
HTML
<p><a class="link-opacity-10-hover" href="#link-opacity">Link hover opacity 10</a></p>
<p><a class="link-opacity-25-hover" href="#link-opacity">Link hover opacity 25</a></p>
<p><a class="link-opacity-50-hover" href="#link-opacity">Link hover opacity 50</a></p>
<p><a class="link-opacity-75-hover" href="#link-opacity">Link hover opacity 75</a></p>
<p><a class="link-opacity-100-hover" href="#link-opacity">Link hover opacity 100</a></p>Link underlines
Underline color
Change the underline's color independent of the link text color.
HTML
<p><a href="#underline-color" class="link-underline-primary">Primary underline</a></p>
<p><a href="#underline-color" class="link-underline-secondary">Secondary underline</a></p>
<p><a href="#underline-color" class="link-underline-success">Success underline</a></p>
<p><a href="#underline-color" class="link-underline-danger">Danger underline</a></p>
<p><a href="#underline-color" class="link-underline-warning">Warning underline</a></p>
<p><a href="#underline-color" class="link-underline-info">Info underline</a></p>
<p><a href="#underline-color" class="link-underline-light">Light underline</a></p>
<p><a href="#underline-color" class="link-underline-dark">Dark underline</a></p>
<p><a href="#underline-color" class="link-underline-gold">Gold underline</a></p>
<p><a href="#underline-color" class="link-underline-navy">Navy underline</a></p>
<p><a href="#underline-color" class="link-underline-cream">Cream underline</a></p>
The theme's three extra colors — gold, navy and cream — get underline
classes too, because they are in the theme-colors map. See Color.
Underline offset
Change the underline's distance from your text. Offset is set in em units to automatically
scale with the element's current font-size.
HTML
<p><a href="#underline-offset">Default link</a></p>
<p><a class="link-offset-1" href="#underline-offset">Offset 1 link</a></p>
<p><a class="link-offset-2" href="#underline-offset">Offset 2 link</a></p>
<p><a class="link-offset-3" href="#underline-offset">Offset 3 link</a></p>| Class | text-underline-offset |
|---|---|
.link-offset-1 | 0.125em |
.link-offset-2 | 0.25em |
.link-offset-3 | 0.375em |
Underline opacity
Change the underline's opacity. Requires adding .link-underline to first set an
rgba() color we use to then modify the alpha opacity.
HTML
<p><a class="link-offset-2 link-underline link-underline-opacity-0" href="#underline-opacity">Underline opacity 0</a></p>
<p><a class="link-offset-2 link-underline link-underline-opacity-10" href="#underline-opacity">Underline opacity 10</a></p>
<p><a class="link-offset-2 link-underline link-underline-opacity-25" href="#underline-opacity">Underline opacity 25</a></p>
<p><a class="link-offset-2 link-underline link-underline-opacity-50" href="#underline-opacity">Underline opacity 50</a></p>
<p><a class="link-offset-2 link-underline link-underline-opacity-75" href="#underline-opacity">Underline opacity 75</a></p>
<p><a class="link-offset-2 link-underline link-underline-opacity-100" href="#underline-opacity">Underline opacity 100</a></p>Hover variants
Just like the .link-opacity-*-hover utilities, .link-offset and
.link-underline-opacity utilities include :hover variants by default. Mix and match
to create unique link styles.
HTML
<a class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="#hover-variants">
Underline opacity 0 → 75 and offset 2 → 3 on hover
</a>The full list of hover classes:
.link-opacity-{10|25|50|75|100}-hover.link-offset-{1|2|3}-hover.link-underline-opacity-{0|10|25|50|75|100}-hover
Colored links
Colored link helpers have been updated to pair with the link utilities. Use the new utilities to modify the link opacity, underline opacity, and underline offset.
HTML
<p><a href="#colored-links" class="link-primary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Primary link</a></p>
<p><a href="#colored-links" class="link-secondary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Secondary link</a></p>
<p><a href="#colored-links" class="link-success link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Success link</a></p>
<p><a href="#colored-links" class="link-danger link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Danger link</a></p>
<p><a href="#colored-links" class="link-warning link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Warning link</a></p>
<p><a href="#colored-links" class="link-info link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Info link</a></p>
<p><a href="#colored-links" class="link-light link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Light link</a></p>
<p><a href="#colored-links" class="link-dark link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Dark link</a></p>
<p><a href="#colored-links" class="link-gold link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Gold link</a></p>
<p><a href="#colored-links" class="link-navy link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Navy link</a></p>
<p><a href="#colored-links" class="link-cream link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Cream link</a></p>
<p><a href="#colored-links" class="link-body-emphasis link-offset-2 link-underline-opacity-25 link-underline-opacity-75-hover">Emphasis link</a></p>.link-light, .link-cream and .link-warning (gold-300) are low contrast
on the cream page background. Use them on a dark surface such as .text-bg-navy or inside a
data-bs-theme="dark" region.CSS
The link utilities write custom properties that the colored-link helpers and the base a rule
consume. Overriding the variables on a container changes every link inside it.
"link-opacity": (
css-var: true,
class: link-opacity,
state: hover,
values: (10: .1, 25: .25, 50: .5, 75: .75, 100: 1)
),
"link-offset": (
property: text-underline-offset,
class: link-offset,
state: hover,
values: (1: .125em, 2: .25em, 3: .375em)
),
"link-underline": (
property: text-decoration-color,
class: link-underline,
local-vars: (link-underline-opacity: 1),
values: map-merge($utilities-links-underline, (null: rgba(var(--bs-link-color-rgb), var(--bs-link-underline-opacity, 1))))
),
"link-underline-opacity": (
css-var: true,
class: link-underline-opacity,
state: hover,
values: (0: 0, 10: .1, 25: .25, 50: .5, 75: .75, 100: 1)
),