Skip to content

Keyboard Key

ore-keyboard-key renders a keyboard key hint in compact command UI or as a large key-state display. It is presentational: place it beside text or inside an interactive control rather than treating the key itself as a button.

Compact Keys

The default sm size matches shortcut hints in ore-command-palette.

PreviewCode
RTL
html
<div style="display: flex; gap: 0.25rem; align-items: center;">
  <ore-keyboard-key>⌘</ore-keyboard-key>
  <ore-keyboard-key>K</ore-keyboard-key>
</div>

<script type="module">
  import '@vielzeug/refine/keyboard-key';
</script>

Large Keys and Pressed Shortcuts

Use size="lg" for shortcut settings, input visualizers, and other places where key state is the primary content. symbol adds decorative modifier notation above the label. Wrap combinations in ore-keyboard-shortcut; its pressed state draws one continuous surround around every key.

PreviewCode
RTL
html
<ore-keyboard-shortcut pressed>
  <ore-keyboard-key size="lg" symbol="⌘">Command</ore-keyboard-key>
  <ore-keyboard-key size="lg" symbol="⇧">Shift</ore-keyboard-key>
  <ore-keyboard-key size="lg">K</ore-keyboard-key>
</ore-keyboard-shortcut>

<script type="module">
  import '@vielzeug/refine/keyboard-key';
</script>

Toggle the wrapper as the complete shortcut is pressed:

js
const shortcut = document.querySelector('ore-keyboard-shortcut');

window.addEventListener('keydown', event => {
  shortcut.toggleAttribute('pressed', event.metaKey && event.shiftKey && event.key.toLowerCase() === 'k');
});

window.addEventListener('keyup', () => {
  shortcut.removeAttribute('pressed');
});

Set pressed directly on ore-keyboard-key only when displaying one independently pressed key.

API Reference

ore-keyboard-key Attributes

AttributeTypeDefaultDescription
size'sm' | 'lg''sm'Compact hint or large key-state display
symbolstringDecorative notation shown in the large key's upper corner
pressedbooleanfalseShows the key in its pressed visual state

ore-keyboard-key Slots and Parts

SurfaceNameDescription
Slot(default)Visible key label
PartkeyInternal <kbd> element

ore-keyboard-shortcut API

SurfaceNameTypeDefaultDescription
AttributepressedbooleanfalseDraws one pressed surround around every grouped key
Slot(default)Keyboard keys in shortcut order
PartshortcutGrouping surface around the slotted keys

CSS Custom Properties

PropertyDefaultDescription
--keyboard-key-bgTheme-dependentKey surface color
--keyboard-key-colorTheme-dependentKey label color
--keyboard-key-border-colorTheme-dependentKey border color
--keyboard-key-radiusSize-dependentKey corner radius
--keyboard-key-font-familySize-dependentKey label typeface
--keyboard-key-font-sizeSize-dependentKey label size
--keyboard-key-font-weightSize-dependentKey label weight
--keyboard-key-padding-blockSize-dependentVertical padding
--keyboard-key-padding-inlineSize-dependentHorizontal padding
--keyboard-key-min-widthvar(--size-16) for lgLarge key minimum width
--keyboard-key-min-heightvar(--size-16) for lgLarge key minimum height
--keyboard-key-shadowSize-dependentKey shadow
--keyboard-key-symbol-colorTheme-dependentLarge modifier symbol color
--keyboard-key-pressed-ring-colorTheme-dependentIndividual pressed-key surround color
--keyboard-shortcut-gapvar(--size-2)Space between grouped keys
--keyboard-shortcut-paddingvar(--size-2)Space between keys and the group surround
--keyboard-shortcut-radiusvar(--rounded-lg)Group surround corner radius
--keyboard-shortcut-pressed-bgTheme-dependentPressed group surround color
--keyboard-shortcut-pressed-border-colorTheme-dependentPressed group border color

Accessibility

Each key renders a native <kbd> element. The shortcut wrapper groups its keys visually without adding an interactive role or focus behavior. Keep a visible text label in every key's default slot; symbol is decorative and hidden from assistive technology. When a live key visualizer communicates input state, announce the current shortcut separately if screen-reader users need that feedback.