Icon link
Quickly create stylized hyperlinks with Bootstrap Icons or other icons.
The icon link helper component modifies our default link styles to enhance their appearance and quickly align any pairing of icon and text. Alignment is set via inline flexbox styling and a default gap
value. We stylize the underline with a custom offset and color. Icons are automatically sized to 1em
to best match their associated text’s font-size
.
Icon links assume Bootstrap Icons are being used, but you can use any icon or image you like.
aria-hidden="true"
, as we’ve done in our examples. For icons that convey meaning, provide an appropriate text alternative by adding role="img"
and an appropriate aria-label="..."
to the SVGs.
Example
Take a regular <a>
element, add .icon-link
, and insert an icon on either the left or right of your link text. The icon is automatically sized, placed, and colored.
<a class="icon-link" href="#">
<svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#person-circle"/>
</svg>
<span class="icon-link-text">Icon link</span>
</a>
<a class="icon-link" href="#">
<span class="icon-link-text">Icon link</span>
<svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#arrow-right"/>
</svg>
</a>
Style on hover
Add .icon-link-hover
to move the icon to the right on hover.
<a class="icon-link icon-link-hover" href="#">
<span class="icon-link-text">Icon link</span>
<svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#arrow-right"/>
</svg>
</a>
Customize
Modify the styling of an icon link with our link CSS variables, Sass variables, utilities, or custom styles.
CSS variables
Modify the --bs-link-*
and --bs-icon-link-*
CSS variables as needed to change the default appearance.
Customize the hover transform
by overriding the --bs-icon-link-transform
CSS variable:
<a class="icon-link icon-link-hover" style="--bs-icon-link-transform: translate3d(0, -.125rem, 0);" href="#">
<span class="icon-link-text">Icon link</span>
<svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#arrow-right"/>
</svg>
</a>
Customize the color by overriding the --bs-link-*
CSS variable:
<a class="icon-link icon-link-hover" style="--bs-link-hover-color-rgb: 25, 135, 84;" href="#">
<span class="icon-link-text">Icon link</span>
<svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#arrow-right"/>
</svg>
</a>
Sass variables
Customize the icon link Sass variables to modify all icon link styles across your Bootstrap-powered project.
$icon-link-gap: .375rem;
$icon-link-underline-offset: .25em;
$icon-link-icon-size: 1em;
$icon-link-icon-transition: .2s ease-in-out transform;
$icon-link-icon-transform: translate3d(.25em, 0, 0);
Sass utilities API
Modify icon links with any of our link utilities for modifying underline color and offset.
<a class="icon-link icon-link-hover link-success link-underline-success link-underline-opacity-25" href="#">
<span class="icon-link-text">Icon link</span>
<svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#arrow-right"/>
</svg>
</a>