Kbd New Alpha Light DOM & Tailwind

Open in Storybook

Displays a keyboard key, such as a shortcut or a key the user should press.

OverviewUsageCompositionExamplesAccessibilityAPI referencePartsDesign guidelines
This component is considered alpha. We're still finalising the API, so it may include a breaking change at any time — use it at your own risk.
Loading...

Usage

Kbd displays a keyboard key, such as a shortcut or a key the user should press. Group the keys of a multi-key shortcut together with Kbd Group.

Import the parts you need — each import registers its custom element:

Copy code
import "@nordhealth/components/lib/Kbd"
import "@nordhealth/components/lib/KbdGroup"

Then place a key, or group several together:

Composition

Kbd renders a single key. To represent a multi-key shortcut, wrap several keys in a Kbd Group.

Copy code
KbdGroup
├── Kbd
└── Kbd
Copy code
<nord-kbd-group>
  <nord-kbd>Ctrl</nord-kbd>
  <nord-kbd>K</nord-kbd>
</nord-kbd-group>

Kbd Group

Kbd Group lays out a set of Kbd keys together, for example to represent a multi-key shortcut such as Ctrl K. The default slot accepts Kbd elements, and you can place other inline content such as a + separator between them.

Examples

Inline in text

A Kbd Group reads naturally inline within a sentence to describe a shortcut.

Inside a button

Place a Kbd inside a Button to surface the key that triggers it.

Inside an input

Use a Kbd Group in an Input end slot to hint at the shortcut that focuses the field.

Inside a tooltip

Show the keyboard shortcut for an action inside a Tooltip.

RTL

Kbd follows the document or container direction. Toggle the direction to see the layout mirror.

Accessibility

  • Use Kbd for keyboard keys and shortcuts only — for inline code, use a <code> element instead so assistive technology conveys the right meaning.
  • Don't rely on Kbd alone to convey an action; always pair it with a descriptive label, such as the button or menu text it sits beside.
  • Use the same casing and symbols the user sees on their physical keyboard so the displayed key matches what they press.

API reference

Kbd

Kbd is used to display a keyboard key, such as a shortcut or a key the user should press. Group related keys together with Kbd Group.

<nord-kbd></nord-kbd>

Props

PropertyAttribute Description TypeDefault
sizesizeThe size of the key. Each value maps to the matching font-size token (xs--n-font-size-xsl--n-font-size-l); xs suits dense surfaces like dark tooltips, l is for more prominent keys.'xs' | 's' | 'm' | 'l''m'
variantvariantThe colour variant. default follows the active layout theme; light and dark pin the key to fixed light/dark colours regardless of the theme (e.g. a dark key on a dark tooltip).'default' | 'light' | 'dark''default'
borderlessborderlessRemoves the border and drop shadow, for a flat key with no outline.booleanfalse
emphasizeemphasizeRaises the text contrast — the theme's main text colour (--n-color-text) on the default variant, or the pinned high-contrast colour (dark text / white) on the fixed light / dark variants.booleanfalse

Slots

Slot name Description
Default slotDefault slot for the key label (text or an icon).

CSS Properties

CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.

PropertyDescriptionDefault
--n-kbd-colorControls the text color of the key.var(--n-color-icon)
--n-kbd-background-colorControls the background color of the key.var(--n-color-button)
--n-kbd-padding-blockControls the block padding of the key. Overrides the size default.
--n-kbd-padding-inlineControls the inline padding of the key. Overrides the size default.
--n-kbd-font-sizeControls the font size of the key. Overrides the size default.
--n-kbd-border-radiusControls how rounded the corners are.var(--n-border-radius-s)
--n-kbd-border-widthControls the border width of the key.1px
--n-kbd-border-colorControls the border color of the key. Overrides the variant default.
--n-kbd-box-shadowControls the box shadow of the key. Overrides the variant default.
Light DOM & Tailwind. This component renders in the light DOM, so you can style it directly with your own CSS or Tailwind utility classes — there is no shadow boundary, and its default styles are low specificity, so your utilities win.

Parts

This component is made up of the following parts.

Kbd Group

Kbd Group lays out a set of Kbd keys together, for example to represent a multi-key shortcut such as Ctrl K.

<nord-kbd-group></nord-kbd-group>

Slots

Slot name Description
Default slotDefault slot for Kbd elements.
Design guidelinesFor designers

Usage

This section includes guidelines for designers and developers about the usage of this component in different contexts.

Do

  • Use to display a keyboard key or shortcut, such as K.
  • Group the keys of a multi-key shortcut together with Kbd Group.
  • Use the same casing and symbols the user sees on their keyboard.

Don’t

  • Don’t use to style arbitrary inline code, use a <code> element instead.
  • Don’t rely on Kbd alone to convey an action, always pair it with a descriptive label.

Was this page helpful?

Yes No

We use this feedback to improve our documentation.