Kbd

Shows a keyboard key or shortcut, such as Ctrl C.

Shift + Tab

Usage

Code
import { Kbd } from '@leverui/components';
Code
<Kbd>F12</Kbd>

Examples

Combinations

Render Kbd to showcase key combinations

ctrl+shift+del

Group

Use KbdPropsProvider to group the keys of a shortcut. Its size and variant apply to every key inside.

⌘KCtrl+Shift+P

Function Keys

Here's an example of using Kbd to showcase function keys

⌘⌥⇧⌃

Variants

Use the variant prop to change the appearance of the Kbd component

Shift + TabShift + TabShift + TabShift + Tab

Sizes

Use the size prop to change the size of the Kbd component

Shift + TabShift + TabShift + Tab

Within Text

Use Kbd within text to highlight key combinations

Press F12 to open DevTools

Guides

Semantics

Renders a <kbd> element. Adds no role and no keyboard behavior. Defaults: size="md" and variant="raised". size and variant are responsive.

Code
<Kbd size={{ base: 'sm', md: 'lg' }} variant="outline" colorPalette="blue">
  ⌘
</Kbd>

Provider defaults

KbdPropsProvider sets default props for the keys inside it. Defaults are reactive. A prop on a Kbd wins. Defaults can include HTML attributes, styles, an as tag, and a children function, but not ref or asChild.

Code
import { Kbd, KbdPropsProvider } from '@leverui/components';

<KbdPropsProvider value={{ size: 'sm', variant: 'outline' }}>
  <Kbd>Esc</Kbd>
  <Kbd size="lg">Enter</Kbd>
</KbdPropsProvider>;

Pass children as a function that returns new JSX. It runs for every Kbd. JSX shared directly would move one DOM node from one Kbd to the next.

Code
function renderSharedKey() {
  return <span>Esc</span>;
}

<KbdPropsProvider value={{ children: renderSharedKey }}>
  <Kbd />
  <Kbd />
</KbdPropsProvider>;

Props

PropDefaultTypeDescription
colorPalettegraystringColor palette, built-in or your own.
variantraised'raised' | 'outline' | 'subtle' | 'plain' or responsive mapKey style.
sizemd'sm' | 'md' | 'lg' or responsive mapKey size.
askbdNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the key's props.
unstyledfalsebooleanTurn off the Lever UI styles.

Also accepts the standard HTML attributes, including class and style.

Customize with CSS

Style .leverui-kbd, or select its data-size and data-variant attributes. Import @leverui/components/styles.css once and load your stylesheet after it.

No general style props, CSS objects, or custom recipes. Use CSS theming.