Added in v5.3

Link

Link utilities are used to stylize your anchors to adjust their color, opacity, underline offset, underline color, and more.

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.

Link - 图1

html

  1. <p><a class="link-opacity-10" href="#">Link opacity 10</a></p>
  2. <p><a class="link-opacity-25" href="#">Link opacity 25</a></p>
  3. <p><a class="link-opacity-50" href="#">Link opacity 50</a></p>
  4. <p><a class="link-opacity-75" href="#">Link opacity 75</a></p>
  5. <p><a class="link-opacity-100" href="#">Link opacity 100</a></p>

You can even change the opacity level on hover.

Link - 图2

html

  1. <p><a class="link-opacity-10-hover" href="#">Link hover opacity 10</a></p>
  2. <p><a class="link-opacity-25-hover" href="#">Link hover opacity 25</a></p>
  3. <p><a class="link-opacity-50-hover" href="#">Link hover opacity 50</a></p>
  4. <p><a class="link-opacity-75-hover" href="#">Link hover opacity 75</a></p>
  5. <p><a class="link-opacity-100-hover" href="#">Link hover opacity 100</a></p>

Underline color

Change the underline’s color independent of the link text color.

Link - 图3

html

  1. <p><a href="#" class="link-underline-primary">Primary underline</a></p>
  2. <p><a href="#" class="link-underline-secondary">Secondary underline</a></p>
  3. <p><a href="#" class="link-underline-success">Success underline</a></p>
  4. <p><a href="#" class="link-underline-danger">Danger underline</a></p>
  5. <p><a href="#" class="link-underline-warning">Warning underline</a></p>
  6. <p><a href="#" class="link-underline-info">Info underline</a></p>
  7. <p><a href="#" class="link-underline-light">Light underline</a></p>
  8. <p><a href="#" class="link-underline-dark">Dark underline</a></p>

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.

Link - 图4

html

  1. <p><a href="#">Default link</a></p>
  2. <p><a class="link-offset-1" href="#">Offset 1 link</a></p>
  3. <p><a class="link-offset-2" href="#">Offset 2 link</a></p>
  4. <p><a class="link-offset-3" href="#">Offset 3 link</a></p>

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.

Link - 图5

html

  1. <p><a class="link-offset-2 link-underline link-underline-opacity-0" href="#">Underline opacity 0</a></p>
  2. <p><a class="link-offset-2 link-underline link-underline-opacity-10" href="#">Underline opacity 10</a></p>
  3. <p><a class="link-offset-2 link-underline link-underline-opacity-25" href="#">Underline opacity 25</a></p>
  4. <p><a class="link-offset-2 link-underline link-underline-opacity-50" href="#">Underline opacity 50</a></p>
  5. <p><a class="link-offset-2 link-underline link-underline-opacity-75" href="#">Underline opacity 75</a></p>
  6. <p><a class="link-offset-2 link-underline link-underline-opacity-100" href="#">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.

Link - 图6

html

  1. <a class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="#">
  2. Underline opacity 0
  3. </a>

Colored link helpers have been updated to pair with our link utilities. Use the new utilities to modify the link opacity, underline opacity, and underline offset.

Link - 图7

html

  1. <p><a href="#" class="link-primary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Primary link</a></p>
  2. <p><a href="#" class="link-secondary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Secondary link</a></p>
  3. <p><a href="#" class="link-success link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Success link</a></p>
  4. <p><a href="#" class="link-danger link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Danger link</a></p>
  5. <p><a href="#" class="link-warning link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Warning link</a></p>
  6. <p><a href="#" class="link-info link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Info link</a></p>
  7. <p><a href="#" class="link-light link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Light link</a></p>
  8. <p><a href="#" class="link-dark link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover">Dark link</a></p>
  9. <p><a href="#" class="link-body-emphasis link-offset-2 link-underline-opacity-25 link-underline-opacity-75-hover">Emphasis link</a></p>

Accessibility tip: Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies like screen readers. Please ensure the meaning is obvious from the content itself (e.g., the visible text with a sufficient color contrast) or is included through alternative means, such as additional text hidden with the .visually-hidden class.

CSS

In addition to the following Sass functionality, consider reading about our included CSS custom properties (aka CSS variables) for colors and more.

Sass utilities API

Link utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.

scss/_utilities.scss

  1. "link-opacity": (
  2. css-var: true,
  3. class: link-opacity,
  4. state: hover,
  5. values: (
  6. 10: .1,
  7. 25: .25,
  8. 50: .5,
  9. 75: .75,
  10. 100: 1
  11. )
  12. ),
  13. "link-offset": (
  14. property: text-underline-offset,
  15. class: link-offset,
  16. state: hover,
  17. values: (
  18. 1: .125em,
  19. 2: .25em,
  20. 3: .375em,
  21. )
  22. ),
  23. "link-underline": (
  24. property: text-decoration-color,
  25. class: link-underline,
  26. local-vars: (
  27. "link-underline-opacity": 1
  28. ),
  29. values: map-merge(
  30. $utilities-links-underline,
  31. (
  32. null: rgba(var(--#{$prefix}link-color-rgb), var(--#{$prefix}link-underline-opacity, 1)),
  33. )
  34. )
  35. ),
  36. "link-underline-opacity": (
  37. css-var: true,
  38. class: link-underline-opacity,
  39. state: hover,
  40. values: (
  41. 0: 0,
  42. 10: .1,
  43. 25: .25,
  44. 50: .5,
  45. 75: .75,
  46. 100: 1
  47. ),
  48. ),