Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Kbd

    Keycap for keyboard shortcuts using the native kbd element, in two sizes, with key combinations rendered as separate keys.

    Press Ctrl+K to search, or Esc to close.

    Press Ctrl+K to search, or Esc to close.

    Press Ctrl+K to search, or Esc to close.

    Press Ctrl+K to search, or Esc to close.

    Press Ctrl+K to search, or Esc to close.

    <p class="flex flex-wrap items-center gap-1.5 text-sm text-ink">
        Press <x-markas.kbd :keys="['Ctrl', 'K']" /> to search, or <x-markas.kbd>Esc</x-markas.kbd> to close.
    </p>
    import { Kbd } from "@/components/markas/Kbd";
    
    export default function KbdExample() {
      return (
        <p className="flex flex-wrap items-center gap-1.5 text-sm text-ink">
          Press <Kbd keys={["Ctrl", "K"]} /> to search, or <Kbd>Esc</Kbd> to close.
        </p>
      );
    }
    <script setup lang="ts">
    import Kbd from "@/components/markas/Kbd.vue";
    </script>
    
    <template>
      <p class="flex flex-wrap items-center gap-1.5 text-sm text-ink">
        Press <Kbd :keys="['Ctrl', 'K']" /> to search, or <Kbd>Esc</Kbd> to close.
      </p>
    </template>
    <script lang="ts">
      import Kbd from "$lib/components/markas/Kbd.svelte";
    </script>
    
    <p class="flex flex-wrap items-center gap-1.5 text-sm text-ink">
      Press <Kbd keys={["Ctrl", "K"]} /> to search, or <Kbd>Esc</Kbd> to close.
    </p>
    ---
    import Kbd from "@/components/markas/Kbd.astro";
    ---
    
    <p class="flex flex-wrap items-center gap-1.5 text-sm text-ink">
      Press <Kbd keys={["Ctrl", "K"]} /> to search, or <Kbd>Esc</Kbd> to close.
    </p>
    import { Component } from "@angular/core";
    import { Kbd } from "./markas/kbd.component";
    
    @Component({
      selector: "markas-example",
      imports: [Kbd],
      template: `
        <p class="flex flex-wrap items-center gap-1.5 text-sm text-ink">
          Press <kbd markas-kbd [keys]="['Ctrl', 'K']"></kbd> to search, or
          <kbd markas-kbd>Esc</kbd> to close.
        </p>
      `,
    })
    export default class KbdExample {}

    Examples

    Sizes

    Enter Shift+Tab
    Enter Shift+Tab
    EnterShift+Tab
    EnterShift+Tab
    EnterShift+Tab
    EnterShift+Tab
    Enter Shift+Tab
    Enter Shift+Tab
    EnterShift+Tab
    EnterShift+Tab

    Shortcut list

    Search
    Ctrl+K
    New document
    Ctrl+Alt+N
    Go to next page
    GthenN
    Show shortcuts
    ?
    Search
    Ctrl+K
    New document
    Ctrl+Alt+N
    Go to next page
    GthenN
    Show shortcuts
    ?
    Search
    Ctrl+K
    New document
    Ctrl+Alt+N
    Go to next page
    GthenN
    Show shortcuts
    ?
    Search
    Ctrl+K
    New document
    Ctrl+Alt+N
    Go to next page
    GthenN
    Show shortcuts
    ?
    Search
    Ctrl+K
    New document
    Ctrl+Alt+N
    Go to next page
    GthenN
    Show shortcuts
    ?

    In a search button

    Installation

    npx markasui@latest add kbd

    Usage

    <x-markas.kbd>Esc</x-markas.kbd>
    <x-markas.kbd :keys="['Ctrl', 'K']" />
    <x-markas.kbd size="sm" :keys="['G', 'N']" separator="then" />
    import { Kbd } from "@/components/markas/Kbd";
    
    <Kbd>Esc</Kbd>
    <Kbd keys={["Ctrl", "K"]} />
    <Kbd size="sm" keys={["G", "N"]} separator="then" />
    <template>
      <Kbd>Esc</Kbd>
      <Kbd :keys="['Ctrl', 'K']" />
      <Kbd size="sm" :keys="['G', 'N']" separator="then" />
    </template>
    <script lang="ts">
      import Kbd from "$lib/components/markas/Kbd.svelte";
    </script>
    
    <Kbd>Esc</Kbd>
    <Kbd keys={["Ctrl", "K"]} />
    <Kbd size="sm" keys={["G", "N"]} separator="then" />
    ---
    import Kbd from "@/components/markas/Kbd.astro";
    ---
    
    <Kbd>Esc</Kbd>
    <Kbd keys={["Ctrl", "K"]} />
    <Kbd size="sm" keys={["G", "N"]} separator="then" />
    import { Component } from "@angular/core";
    import { Kbd } from "./markas/kbd.component";
    
    @Component({
      selector: "app-example",
      imports: [Kbd],
      template: `
        <kbd markas-kbd>Esc</kbd>
        <kbd markas-kbd [keys]="['Ctrl', 'K']"></kbd>
        <kbd markas-kbd size="sm" [keys]="['G', 'N']" separator="then"></kbd>
      `,
    })
    export class Example {}

    Angular uses an attribute selector on the native kbd, so class and aria-hidden stay on it.

    • No JavaScript needed. The Blade version does not need Alpine.js.
    • keys renders <kbd><kbd>Ctrl</kbd><span>+</span><kbd>K</kbd></kbd>. Without keys, the slot or children fill a single keycap.
    • Inside a button that already has a name, add aria-hidden="true" so the shortcut is not read twice.
    • The default separator is ”+”. Change it with separator, for example “then” for key sequences.

    Props

    NameTypeDefaultDescription
    size'sm' | 'md'mdKeycap height and text size. Use sm inside buttons and inputs.
    keysstring[][]Key combination. Each key renders as its own keycap inside an outer kbd. Replaces the slot or children.
    separatorstring+Muted text between the keys of a combination, such as "then" for a key sequence.
    children / slotReactNode / slot / snippet-Content of a single keycap when keys is empty.

    Accessibility

    • Uses the native kbd element; a combination nests one kbd per key inside an outer kbd, as the HTML spec recommends.
    • The separator is plain text, so screen readers announce combinations such as "Ctrl + K".
    • Set aria-hidden on the keycap when the shortcut is only a visual hint inside a control that already has a name.

    Related components

    More data components with the same classes in every framework.