shadcn.io is not affiliated with official shadcn/ui
Button examples · Secondary
Button with Kbd (Secondary) for React
A muted button with a keyboard hint beside the label, when a supporting action has a keyboard shortcut worth showing.
Secondary fill, the label, and a kbd showing ⌘K. Nothing in the demo listens for that chord.
Use it when the shortcut exists and this button is not the main one in the row. Show the keys people actually press. A lone Kbd is enough if there is nothing to click. In React, Base UI does not attach the listener.
Preview
Installation
FAQ
Does pressing ⌘K activate this Button?
No. Kbd draws the characters ⌘K. It doesn't register a listener, and it's pointer-events-none, so the click still hits the button. The shortcut itself belongs in your own handler.
How do I show a different shortcut?
Change the children of Kbd. The demo doesn't translate Mac and Windows keys, so write the label for the platform you mean, such as Ctrl B when a symbol would be unclear.
How is the key cap colored here?
variant="secondary" is the quieter fill. The cap adds bg-background so it separates from that fill. The text inside is still ⌘K.
Can I put the shortcut before the label?
Yes. Move Kbd ahead of the text. In this demo it follows the label, which is the usual place for a hint on the trailing side.
Related
- Button with Count (Secondary)A count, kept quiet
- Button with Left Icon (Secondary)An icon, kept quiet
- Button with Right Icon (Secondary)An arrow, kept quiet
- Button with Text (Secondary)Quieter than the main action
- Loading Button (Secondary)A side action, while it runs
- Rounded Button (Secondary)A pill, kept quiet