Link Button
A lightweight, versatile component designed for text links with button-like behavior. Built on Radix UI's Slot primitive, it supports various styles, sizes, and states with minimal visual footprint.
Installation
Add Link Button to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
LinkButton.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 LinkButton component
Copy this code to create your LinkButton 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
Colors
Set the intent with the color prop. Use primary for main actions, neutral for secondary actions, destructive for destructive operations, and success for confirmation actions. The older variant prop (and danger) is still accepted as a deprecated alias.
Underline
Add permanent underlines to link buttons for increased visibility and to match traditional hyperlink styling expectations. By default, underlines only appear on hover and keyboard focus, but using the underline prop makes them permanently visible.
Sizes
LinkButton provides size options to fit various UI contexts. Choose md (default) for standard text links and sm for more compact interfaces or when space is limited. The legacy names medium and small are still accepted.
With Icons
Enhance your link buttons with icons for improved visual communication. Place LinkButton.Icon before or after the text, or on both sides; its position is simply its place among the children. Icons are decorative (aria-hidden) and follow the link button's size unless you pass their own size.
API Reference
LinkButton renders a <button>, a Next.js link (with href), or your own element (with asChild, via the Radix UI Slot primitive). It shows the shared keyboard focus ring. See the Radix UI Slot documentation for more details on the base component.
LinkButton.Root
Main link button component with support for various colors and sizes. It also accepts the native attributes of the element it renders.
See Radix UI docs for base props.
| Prop | Type | Default | Description |
|---|---|---|---|
color | "primary""neutral""destructive""success" | "primary" | Intent colour of the link button |
variant | "primary""neutral""destructive""success""danger" | "undefined" | Deprecated alias for color (danger = destructive). color wins when both are set. |
size | "md""sm" | "md" | Size of the link button. The legacy names medium and small are still accepted. |
underline | "boolean" | "false" | Show the underline permanently instead of only on hover and keyboard focus |
href | "string" | "undefined" | Renders a Next.js link. Without href (and without asChild) a <button type="button"> is rendered. |
disabled | "boolean" | "false" | Disables the button. A disabled link is rendered without href and with aria-disabled. |
asChild | "boolean" | "false" | Render the single child element (e.g. your own link) with the link button styles and props merged onto it |
LinkButton.Icon
Adds a decorative icon to the link button, sized to match it.
| Prop | Type | Default | Description |
|---|---|---|---|
as | "React.ElementType" | ""span"" | Icon component or element type to render, e.g. as={RiArrowRightSLine} |
size | "md""sm" | "inherited" | Overrides the size inherited from LinkButton.Root |