Skip to main content

Helpers

Icon link

Align an inline SVG with link text, and slide it on hover — with no icon font required.

How it works

.icon-link is an inline-flex link with a 0.375rem gap, a faded underline (--bs-link-opacity defaults to .5) and an underline offset of .25em. Any direct child with the class .bi is sized to 1em, filled with currentcolor and given a transform transition.

The theme does not ship Bootstrap Icons. Use an inline <svg class="bi"> with your own path — the class is only a hook, not a font. Mark decorative icons aria-hidden="true".

HTML
<a class="icon-link" href="#!">
  <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/></svg>
  Icon link
</a>

Icons can go on either side.

HTML
<a class="icon-link" href="#!">
  Full results
  <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/></svg>
</a>

Hover

Add .icon-link-hover and the icon moves .25em to the right on hover and :focus-visible. The motion is disabled under prefers-reduced-motion.

HTML
<a class="icon-link icon-link-hover" href="#!">
  Card of the night
  <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/></svg>
</a>

Change the direction or distance with --bs-icon-link-transform. Put the icon first and push it left for a "back" link, or scale it for an external-link glyph.

HTML
<p>
  <a class="icon-link icon-link-hover" style="--bs-icon-link-transform: translate3d(-.25em, 0, 0)" href="#!">
    <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8z"/></svg>
    Back to the roster
  </a>
</p>
<p class="mb-0">
  <a class="icon-link icon-link-hover" style="--bs-icon-link-transform: translate3d(.125em, -.125em, 0)" href="#!">
    External box office
    <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg>
  </a>
</p>

Because the icon is filled with currentcolor, the colored link helpers and the link utilities apply to both text and icon.

HTML
<p>
  <a class="icon-link icon-link-hover link-primary link-underline-opacity-25 link-underline-opacity-100-hover" href="#!">
    Gold icon link
    <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/></svg>
  </a>
</p>
<p class="mb-0">
  <a class="icon-link icon-link-hover link-navy link-offset-2" href="#!">
    Navy icon link
    <svg class="bi" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/></svg>
  </a>
</p>

CSS

.icon-link {
  display: inline-flex;
  gap: 0.375rem;
  align-items: center;
  text-decoration-color: rgba(var(--bs-link-color-rgb), var(--bs-link-opacity, 0.5));
  text-underline-offset: 0.25em;
}
.icon-link > .bi {
  flex-shrink: 0;
  width: 1em;
  height: 1em;
  fill: currentcolor;
  transition: 0.2s ease-in-out transform;
}
.icon-link-hover:hover > .bi,
.icon-link-hover:focus-visible > .bi {
  transform: var(--bs-icon-link-transform, translate3d(0.25em, 0, 0));
}

.icon-link also sets backface-visibility: hidden to keep the icon crisp while it moves. The transition is Bootstrap's fixed 0.2s ease-in-out, not the theme's --bs-transition-base.