Skip to content
TopClass UI

Kbd

A keycap for a key the reader presses, rendered on the server. A combination is sibling keys, with no group part and no plus.

server - 0 KB

Kbd

server - 0 KB

A keycap for a key the reader presses, rendered on the server. A combination is sibling keys, with no group part and no plus.

Install
KTabCtrlShiftEnterEsc

The code

kbd.tsx
import { Kbd } from 'topclassui/kbd'

export default function Demo() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Kbd>K</Kbd>
      <Kbd>Tab</Kbd>
      <Kbd>Ctrl</Kbd>
      <Kbd>Shift</Kbd>
      <Kbd>Enter</Kbd>
      <Kbd>Esc</Kbd>
    </div>
  )
}

An icon inside a key is an <Svg> with no size: at its 1em default it follows the key's own text.

Import from the package

topclassui/kbd
import { Kbd } from 'topclassui/kbd'

Install once:npm i topclassui@beta zod

Examples

  • To name a key the reader presses, inside running text or beside a menu item. It is one <kbd> with a keycap look and no props of its own.
  • A combination is sibling keys separated by a space. For the nested form of the HTML spec, wrap the keys in a plain <kbd> yourself.
keys
KTabCtrlShiftEnterEsc
combination

Press Ctrl K to open the command palette.

Press Shift Tab to move focus backwards.

with-icon

Press K to open the command palette.

nested

Press Shift Tab to move focus backwards.

In Arabic, right to left

اضغط Ctrl K لفتح لوحة الأوامر.

اضغط Shift Tab للرجوع إلى العنصر السابق.

Props

No props of its own: it takes the attributes of the element it renders.

Keyboard and accessibility

Nothing to operate: it is not interactive on its own.

  • It is not a control: it takes no focus and has no states.
  • A screen reader reads the key's text, so give an icon key a text name of its own, as with-icon names its icon "Command".

Right to left

Key names stay in Latin; the keys of a combination follow the sentence, so in Arabic the first key sits at the right.

Server and client

Renders on the server and ships no JavaScript.

Files: index.tsx.

On the chip: server - 0 KB.