shadcn.io is an independent project built on shadcn/ui
Buttons
ProUnderline Button for Svelte UI SDK
A text button whose underline grows from the center on hover, for nav and quiet actions. For Svelte with UI SDK, when a link needs a clear hover.
On this page7 sections
The button is just its label until the pointer arrives or it takes keyboard focus; then a line grows under the text, from the middle or from either side, and shrinks back when it leaves. On the current page's link it stays drawn.
Use it for navigation, footer links, page menus, or a secondary action next to a filled one. It starts as a ghost button with the hover background turned off, and it wraps the Button, so variant and size work as usual. The line is a CSS transition on its scale, with no animation library and no JavaScript; with reduced motion it's drawn full width and fades in instead of growing.
Installation
Usage
<script lang="ts">
import { UnderlineButton } from "@/components/ui/underline-button";
</script>
<UnderlineButton>Read the case study</UnderlineButton>
Demos
Origin
origin sets where the line grows from: center, the default, start or end. Start and end follow the text direction, so in a right-to-left layout the start is on the right.
Thickness and Color
thickness is the line's height in pixels, 2 by default, and underlineColor its color, any CSS color, the primary color by default. Here a hairline in the foreground color suits a footer link, and a thick primary line with a slower duration suits a large call to action.
Current Page
The line stays drawn on a button with aria-current="page" (or "true"), so a menu marks where people are with no extra prop. Screen readers announce it as the current page too.
Accessibility
The underline is decoration and hidden from assistive tech; the label is the button's name. It grows on keyboard focus as well as hover, and the button keeps its usual focus ring. aria-current both draws the line and tells screen readers which item is current.
- Enter
- Activate the button.
- Space
- Activate the button.
FAQ
How do I make the underline thicker?
Set thickness in pixels; 2 is the default. Use 1 for a hairline or 3 to 4 for a bolder line. The Thickness and Color demo shows 1 and 4.
How do I change the underline's color?
Pass underlineColor, any CSS color, such as var(--foreground). The default is the primary color, and the label keeps the button's text color.
Can the line grow from one side?
Yes. origin="start" grows it from where the text starts and origin="end" from where it ends, as in the Origin demo.
How do I keep the underline on the current page's link?
Pass aria-current="page". The line stays drawn while it's set, as in the Current Page demo.
API Reference
UnderlineButton
data-slot="underline-button-line"
children?Snippet
The label; the line is as wide as it is.
clickEffect?boolean
Apply a click effect to the button.
- Default
true
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.
- Default
false
duration?number
How long the underline takes to grow, in milliseconds.
- Default
300
focusableWhenDisabled?boolean
Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.
- Default
false
isLoading?boolean
Show a loading indicator.
- Default
false
onclick?( event: MouseEvent, details?: ButtonActionDetails ) → unknown
Runs when the button is pressed. Return a Promise to keep it pending
(data-pending) until it settles. details.source says how it was
pressed; a wrapper passing the click on may leave it out.
- Type
( event: MouseEvent, details?: ButtonActionDetails ) → unknown- Parameters
event– React.MouseEvent<HTMLButtonElement>details?– ButtonActionDetails- Returns
unknown
origin?"center" | "start" | "end"
Where the underline grows from: the middle of the label, or the side the text starts or ends on (the start is the right in a right-to-left layout).
- Type
"center" | "start" | "end"- Default
"center"
pendingAnnouncement?string
What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
- Default
"Loading"
thickness?number
How thick the underline is, in pixels.
- Default
2
type?"button" | "reset" | "submit"
What a native button does in a form: "submit" submits it and "reset" resets it. Ignored when the button renders as something else.
- Type
"button" | "reset" | "submit"- Default
"button"
underlineColor?string
The underline's color, any CSS color.
- Default
"var(--primary)"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
--underline-button-colorstring
The line's color.
--underline-button-durationstring
How long the line takes to grow (300ms).
--underline-button-thicknessstring
The line's thickness (2px).





