The page navigation is complete. You may now navigate the page content as you wish.
Skip to main content

Documentation versions

Other versions
HDS components v7.0.0 is now available! Learn more about the changes in this major release

Focus ring

Focus rings display when interactive components are focused by the user. They are vital for communicating interactivity.

A note about versions

The tokens used here refer to v7.0 or above of the components package, and v6.0 or above of the tokens package. If you are using an older version, refer to the documentation for your version.

How to use this style

We recommend applying the “focus-ring” style to an element using the design token provided as a custom CSS property.

Consumer responsibility

Note that border-radius is not included with this token and needs to be set according to the specs of the UI element. Consider using inherit.

Use the --hds-focus-ring-box-shadow-action design token directly in your CSS definitions. Note that it can only be used with the box-shadow property.

.your-selector {
  // ...your CSS declarations
  &:focus-visible {
    border-radius: inherit;
    box-shadow: var(--hds-focus-ring-box-shadow-action);
  }
}

CSS helper classes

The CSS helper class .hds-focus-ring-box-shadow is a wrapper of the design token. It’s likely you’ll need to use this helper class in composition with other classes (instead of directly in a template) because it’s connected to the element’s “focused” pseudo-state.

To use this class, ensure you’ve imported the relevant CSS file:

// for product applications
@import "~@hashicorp/design-system-tokens/dist/products/css/helpers/focus-ring.css";

// for hashicorp developer platform
@import "~@hashicorp/design-system-tokens/dist/devdot/css/helpers/focus-ring.css";

Examples

Border radius

no radius
with border radius

Colors

action
critical

Focus ring in Carbon

In Carbon, focus rings are slightly different than in HDS:

  • the visual outline is applied inside the element in most cases
  • there is no differentiation for critical interactive elements

Below you can see how the hds-focus-ring-box-shadow CSS helpers are rendered in their "carbonized" versions:

hds/default
action
critical
carbon/light
action
critical
carbon/dark
action
critical

Because Carbon's focus ring is inset, the --hds-focus-ring-box-shadow-*** tokens and the .hds-focus-ring-box-shadow-*** CSS helpers must be applied directly to an element when the element has a background color, and not to a parent, otherwise the box shadow that renders the focus ring will be hidden behind the element's background.