Skip to content

ComponentsActions

SourceSource

Keyboard Shortcut Tag

A small monospace tag for displaying keyboard shortcuts.

A small monospace tag for displaying keyboard shortcuts. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.

Root class newt-kbd
import { Kbd } from "@/registry/bases/newt/ui/kbd-tag"

export default function KbdTagDemo() {
  return (
    <div className="flex items-center gap-1">
      <Kbd>Ctrl</Kbd>
      <Kbd>K</Kbd>
    </div>
  )
}
<script setup lang="ts">
import { Kbd } from "~~/registry/bases/newt/ui/kbd-tag"
</script>

<template>
  <div class="flex items-center gap-1">
    <Kbd>Ctrl</Kbd>
    <Kbd>K</Kbd>
  </div>
</template>

Installation

npx newtui@latest add kbd-tagnpx shadcn@latest add @newtui/kbd-tagnpx shadcn-vue@latest add @newtui/kbd-tagpnpm dlx newtui@latest add kbd-tagpnpm dlx shadcn@latest add @newtui/kbd-tagpnpm dlx shadcn-vue@latest add @newtui/kbd-tagyarn dlx newtui@latest add kbd-tagyarn dlx shadcn@latest add @newtui/kbd-tagyarn dlx shadcn-vue@latest add @newtui/kbd-tagbunx newtui@latest add kbd-tagbunx shadcn@latest add @newtui/kbd-tagbunx shadcn-vue@latest add @newtui/kbd-tagdeno run -A npm:newtui@latest add kbd-tagdeno run -A npm:shadcn@latest add @newtui/kbd-tagdeno run -A npm:shadcn-vue@latest add @newtui/kbd-tagvlx newtui@latest add kbd-tagvlx shadcn@latest add @newtui/kbd-tagvlx shadcn-vue@latest add @newtui/kbd-tagvp dlx newtui@latest add kbd-tagvp dlx shadcn@latest add @newtui/kbd-tagvp dlx shadcn-vue@latest add @newtui/kbd-tagnubx newtui@latest add kbd-tagnubx shadcn@latest add @newtui/kbd-tagnubx shadcn-vue@latest add @newtui/kbd-tagnlx newtui@latest add kbd-tagnlx shadcn@latest add @newtui/kbd-tagnlx shadcn-vue@latest add @newtui/kbd-tagupx newtui@latest add kbd-tagupx shadcn@latest add @newtui/kbd-tagupx shadcn-vue@latest add @newtui/kbd-tag

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Copy the source into your project

import * as React from "react"

import { cn } from "@/lib/utils"

const Kbd = React.forwardRef<HTMLElement, React.HTMLAttributes<HTMLElement>>(
  ({ className, ...props }, ref) => (
    <kbd
      ref={ref}
      className={cn(
        "inline-flex h-5 min-w-5 items-center justify-center rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-base px-1.5 font-[family-name:var(--newt-font-mono)] text-[11px] font-semibold text-newt-text-secondary shadow-[0_1px_0_var(--newt-border)]",
        className
      )}
      {...props}
    />
  )
)
Kbd.displayName = "Kbd"

const KbdTag = Kbd

export { Kbd, KbdTag }
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <kbd
    :class="
      cn(
        'inline-flex h-5 min-w-5 items-center justify-center rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-base px-1.5 font-[family-name:var(--newt-font-mono)] text-[11px] font-semibold text-newt-text-secondary shadow-[0_1px_0_var(--newt-border)]',
        props.class
      )
    "
  >
    <slot />
  </kbd>
</template>
export { default as KbdTag } from "./KbdTag.vue"
export { default as Kbd } from "./KbdTag.vue"

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Keyboard Shortcut Tag to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Keyboard Shortcut Tag to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { KbdTag } from "@/components/ui/kbd-tag"

export function Example() {
  return <KbdTag />
}
<script setup lang="ts">
import { KbdTag } from "@/components/ui/kbd-tag"
</script>

<template>
  <KbdTag />
</template>

API reference

Kbd

PropType
children / default slot?React.ReactNode / Vue slot

Content rendered inside the component.

TypeReact.ReactNode / Vue slot
className / class?string

Additional classes merged with the component defaults.

Typestring

The registry exports Kbd, KbdTag. Parts without a table accept the native attributes for the element they render; React uses className, while Vue uses class and fallthrough attributes.

Accessibility

Preserve the native semantics of the rendered elements and pass through ARIA attributes when the surrounding context needs a label or description. Any interactive child needs a visible focus indicator, and meaning must not rely on colour alone.

Tokens

Keyboard Shortcut Tag reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-kbd.

  • --newt-font-mono
  • --newt-text-secondary
  • --newt-bg-base
  • --newt-border
  • --newt-radius-sm