Button Properties
A versatile button component with various styles, sizes, and states. Built on Radix UI's Slot primitive for flexibility and accessibility.
Installation
Add Button to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
Button.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-slotclass-variance-authorityif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Create or update your Button component
Copy this code to create your Button component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Rounded Full
For designs requiring pill-shaped buttons, pass className="rounded-full"; the class is merged last and overrides the default radius. This creates buttons with fully rounded corners, ideal for floating action buttons, icon buttons, or to create visual distinction.
Variants
Buttons come in four visual variants to communicate different levels of emphasis. The default variant has the strongest visual weight, while stroke, lighter, and ghost provide progressively subtler alternatives for secondary actions.
Colors
Colors provide semantic meaning to button actions. Use blue for primary actions, neutral for secondary actions, danger for destructive operations, and success for confirmation or completion actions. Each color can be combined with any variant.
default
stroke
lighter
ghost
Sizes
Buttons are available in four sizes to accommodate different UI contexts. Choose from large, medium (default), small, and x-small to create visual hierarchy or fit specific layout constraints.
With Icons
Enhance visual communication by adding icons to your buttons. The Button.Icon component can be positioned before text, after text, on both sides, or used alone for icon-only buttons. Icons automatically adapt to the button's size.
Icon Examples
The following examples demonstrate how icons adapt to different button sizes, colors, and variants. This comprehensive overview shows all possible combinations to help you choose the right button style for your interface.
default
stroke
lighter
ghost
API Reference
The Button component is built on top of the Radix UI Slot primitive and provides a flexible way to create interactive elements. See the Radix UI Slot documentation for more details on the base component.
Button.Root
Main button component with support for various styles, colors, and sizes.
See Radix UI docs for base props.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default""stroke""lighter""ghost" | "default" | Visual style variant of the button |
color | "primary""neutral""destructive""success" | "primary" | Intent colour. Legacy names blue (= primary) and danger (= destructive) still work but are deprecated |
size | "xs""sm""md""lg" | "md" | Size of the button. Legacy names x-small, small, medium, large still work but are deprecated |
loading | "boolean" | "false" | Disables the button, sets aria-busy and shows a spinner |
disabled | "boolean" | "false" | Whether the button is disabled |
type | "button""submit""reset" | "button" | Native button type. Defaults to button so it never submits a form by accident; pass submit for submit buttons |
href | "string" | "undefined" | Renders a Next.js link styled as a button. A disabled link has no href |
asChild | "boolean" | "false" | Merges the button props onto its single child element (e.g. a link) instead of rendering a <button> |
className | "string" | "undefined" | Merged last, so it can override any style (e.g. rounded-full for a pill shape) |
Button.Icon
Adds an icon to the button with proper sizing and positioning.
| Prop | Type | Default | Description |
|---|---|---|---|
as | "React.ElementType" | "span" | Icon component or element to render, e.g. as={RiArrowRightLine}. Rendered with aria-hidden |
size | "xs""sm""md""lg" | "from Button" | Size of the icon; follows the parent Button's size when omitted. Place it before or after the text to position it |
Used in these blocks
Block families with at least one block built on this component. Each page previews its blocks and lists the components and packages they use.