font-weight
does not work with the Bootstrap 5 Icon Font.
As the Bootstrap Icon documentation mentions, styling is very limited.
Styling
Color can be changed by setting a .text-* class or custom CSS
You can apply a hack by using the non-standard -webkit-text-stroke
, which will resemble bold text.
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css" rel="stylesheet" />
<style>
.bi-hover-bold:hover {
-webkit-text-stroke: 1px;
}
</style>
<p>
<i class="bi-asterisk bi-hover-bold" role="img" aria-label="Required"></i> Bold-like on hover
</p>
<p>
<i class="bi-asterisk" role="img" aria-label="Required"></i> Normal, for comparison
</p>
Warning about bold on hover
This hack does not behave the same as real bold, as it does not change the character’s size. Because font-weight
does change the text flow, it should be avoided on hover, as text might shift or even wrap while hovering.
Warnings on Accessibility
See also Accessibility considerations for Bootstrap Icon
If you want to style hover for an element, it indicates that you probably have some interaction bound to it. Interactive elements need to fit several criteria to be usable by people with disabilities or keyboard fans:
- It needs to be obvious that one can interact with it, visually
- That also needs to be indicated by means of the element’s role, like
button
or link
, to be exposed to assistive technology
- Interaction needs to work with the keyboard as well, being focusable
- To know what activating the element does, it needs an accessible name
For this case it’s best to wrap the icon in a button:
<button type="button" class="btn btn-light" aria-label=""><i class="bi-asterisk"></i></button>
<style>
.btn:hover { -webkit-text-stroke: 1px }
</style>