Helpers
Focus ring
Give any focusable element the theme's gold focus ring, and tune it with CSS variables.
How it works
.focus-ring removes the browser outline on :focus and paints a
box-shadow ring instead. The ring is gold: rgba(184, 148, 31, .4) in light mode
(gold-700 at 40 %) and rgba(212, 175, 55, .4) in dark mode (gold-500). Form controls and
buttons already get the same ring through their own variables; the helper is for links, custom controls and
anything else you make focusable with tabindex.
Tab into the example to see it.
HTML
<a href="#!" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2">Custom focus ring</a>:focus, not :focus-visible, so a mouse click also shows the
ring. If that is unwanted, add your own :focus:not(:focus-visible) override.Customize
Six custom properties control the ring. Set them on the element, or on a parent, with a
style attribute or your own class.
--bs-focus-ring-x: 0; /* offset-x, default 0 */
--bs-focus-ring-y: 0; /* offset-y, default 0 */
--bs-focus-ring-blur: 0; /* blur, default 0 */
--bs-focus-ring-width: .25rem;
--bs-focus-ring-opacity: .4;
--bs-focus-ring-color: rgba(184, 148, 31, .4); /* dark: rgba(212, 175, 55, .4) */
HTML
<a href="#!" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-color: rgba(var(--bs-navy-rgb), .5)">Navy ring, 50 %</a>
<a href="#!" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-width: 2px; --bs-focus-ring-color: var(--bs-primary)">Hard 2px gold ring</a>
<a href="#!" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-x: .25rem; --bs-focus-ring-y: .25rem; --bs-focus-ring-blur: .5rem">Offset and blurred</a>Color
.focus-ring-* sets --bs-focus-ring-color from the theme colour's
-rgb variable at --bs-focus-ring-opacity. All eleven theme colours are generated.
.focus-ring-primary follows the dark-mode gold swap; .focus-ring-gold is always
gold-500.
HTML
<p class="d-flex flex-wrap gap-2 mb-0">
<a href="#!" class="d-inline-flex focus-ring focus-ring-primary py-1 px-2 text-decoration-none border rounded-2">Primary</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-secondary py-1 px-2 text-decoration-none border rounded-2">Secondary</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-success py-1 px-2 text-decoration-none border rounded-2">Success</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-info py-1 px-2 text-decoration-none border rounded-2">Info</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-warning py-1 px-2 text-decoration-none border rounded-2">Warning</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-danger py-1 px-2 text-decoration-none border rounded-2">Danger</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-light py-1 px-2 text-decoration-none border rounded-2">Light</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-dark py-1 px-2 text-decoration-none border rounded-2">Dark</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-gold py-1 px-2 text-decoration-none border rounded-2">Gold</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-navy py-1 px-2 text-decoration-none border rounded-2">Navy</a>
<a href="#!" class="d-inline-flex focus-ring focus-ring-cream py-1 px-2 text-decoration-none border rounded-2">Cream</a>
</p>.focus-ring-light and .focus-ring-cream vanish on the cream page background. Use
them inside a navy region only.Sass
Variables, from the theme's scss/_variables.scss and Bootstrap's defaults:
$focus-ring-width: .25rem;
$focus-ring-opacity: .4; // rb-bootstrap: .4 (stock .25)
$focus-ring-color: rgba($primary, $focus-ring-opacity); // gold-700 at 40%
$focus-ring-blur: 0;
$focus-ring-box-shadow: 0 0 $focus-ring-blur $focus-ring-width $focus-ring-color;
The dark-mode value is re-emitted in scss/_tokens.scss as
--bs-focus-ring-color: rgba($rb-gold-500, $focus-ring-opacity), because
$primary is compiled statically. The colour classes come from the
utility API entry "focus-ring", which reads
$utilities-focus-rings.