The button component is probably the most widely used element in any user interface or website as it can be used to launch an action but also to link to other pages.
Setup
pnpm add @cailabs/components.base <script>
import { Button } from '@cailabs/components.base';
</script> See Installation for umbrella and segment packages.
Default button
Use these default button styles with multiple colors to indicate an action or link within your website.
<script>
import { Button } from '.';
</script>
<Button>Default</Button>
<Button color="alternative">Alternative</Button>
<Button color="dark">Dark</Button>
<Button color="light">Light</Button>
<Button color="blue">Blue</Button>
<Button color="green">Green</Button>
<Button color="red">Red</Button>
<Button color="yellow">Yellow</Button>
<Button color="secondary">Purple</Button> Button with link
You can add a link to a Button component:
Home<script>
import { Button } from '.';
</script>
<Button href="/">Home</Button> Button pills
The button pills can be used as an alternative style by using fully rounded edges.
<script>
import { Button } from '.';
</script>
<Button pill>Default</Button>
<Button color="alternative" pill>Alternative</Button>
<Button color="dark" pill>Dark</Button>
<Button color="light" pill>Light</Button>
<Button color="blue" pill>Blue</Button>
<Button color="green" pill>Green</Button>
<Button color="red" pill>Red</Button>
<Button color="yellow" pill>Yellow</Button>
<Button color="purple" pill>Purple</Button> Gradient monochrome
These beautifully colored buttons built with the gradient color stops utility classes from Tailwind CSS can be used as a creative alternative to the default button styles.
<script>
import { GradientButton } from '.';
</script>
<GradientButton color="blue">Blue</GradientButton>
<GradientButton color="green">Green</GradientButton>
<GradientButton color="cyan">Cyan</GradientButton>
<GradientButton color="teal">Teal</GradientButton>
<GradientButton color="lime">Lime</GradientButton>
<GradientButton color="red">Red</GradientButton>
<GradientButton color="pink">Pink</GradientButton>
<GradientButton color="purple">Purple</GradientButton> Gradient duotone
These buttons use a style that includes two contrasted colors creating an impressive mesh gradient effect.
<script>
import { GradientButton } from '.';
</script>
<GradientButton color="purpleToBlue">Purple to Blue</GradientButton>
<GradientButton color="cyanToBlue">Cyan to Blue</GradientButton>
<GradientButton color="greenToBlue">Green to Blue</GradientButton>
<GradientButton color="purpleToPink">Purple to Pink</GradientButton>
<GradientButton color="pinkToOrange">Pink to Orange</GradientButton>
<GradientButton color="tealToLime">Teal to Lime</GradientButton>
<GradientButton color="redToYellow">Red to Yellow</GradientButton> Gradient outline
This is a special button style that incorporates a gradient color for the outline that can be used as a secondary style to the fully colored gradient buttons.
<script>
import { GradientButton } from '.';
</script>
<GradientButton outline color="purpleToBlue">Purple to Blue</GradientButton>
<GradientButton outline color="cyanToBlue">Cyan to Blue</GradientButton>
<GradientButton outline color="greenToBlue">Green to Blue</GradientButton>
<GradientButton outline color="purpleToPink">Purple to Pink</GradientButton>
<GradientButton outline color="pinkToOrange">Pink to Orange</GradientButton>
<GradientButton outline color="tealToLime">Teal to Lime</GradientButton>
<GradientButton outline pill color="redToYellow">Red to Yellow</GradientButton>
<GradientButton outline color="redToYellow" class="w-72">Red to Yellow</GradientButton> Colored shadows
These beautiful button elements with color shadows can be used since the release of Tailwind v3.0.
<script>
import { Button, GradientButton } from '.';
</script>
<GradientButton shadow color="blue">Blue</GradientButton>
<GradientButton shadow color="green">Green</GradientButton>
<GradientButton shadow color="cyan">Cyan</GradientButton>
<GradientButton shadow color="teal">Teal</GradientButton>
<GradientButton shadow color="lime">Lime</GradientButton>
<GradientButton shadow color="red">Red</GradientButton>
<GradientButton shadow color="pink">Pink</GradientButton>
<GradientButton shadow color="purple">Purple</GradientButton> Outline buttons
Use the following button styles to show the colors only for the border of the element.
<script>
import { Button } from '.';
</script>
<div class="flex justify-center gap-2 flex-wrap">
<Button outline>Default</Button>
<Button outline color="dark">Dark</Button>
<Button outline color="green">Green</Button>
<Button outline color="red">Red</Button>
<Button outline color="yellow">Yellow</Button>
<Button outline color="purple">Purple</Button>
</div> Button sizes with icons
Use these examples if you want to use smaller or larger buttons.
<script>
import { Button } from '.';
</script>
<Button size="xs">
{#snippet leadingIcon()}
<iconify-icon icon="bi:file-check-fill"> </iconify-icon>
{/snippet}
Extra small</Button
>
<Button size="sm">
{#snippet leadingIcon()}
<iconify-icon icon="bi:file-check-fill"> </iconify-icon>
{/snippet}
small</Button
>
<Button size="md">
{#snippet leadingIcon()}
<iconify-icon icon="bi:file-check-fill"> </iconify-icon>
{/snippet}
Base</Button
>
<Button size="lg">
{#snippet leadingIcon()}
<iconify-icon icon="bi:file-check-fill"> </iconify-icon>
{/snippet}
Large</Button
>
<Button size="xl">
{#snippet leadingIcon()}
<iconify-icon icon="bi:file-check-fill"> </iconify-icon>
{/snippet}
Extra Large</Button
> Loader
Use the spinner components to indicate a loader animation inside buttons.
<script>
import { Button, Spinner } from '.';
</script>
<Button loading>
Loading ...
</Button>
Disabled
You can add any additional button attributes. The following example shows adding the disabled attribute.
<script>
import { Button } from '.';
</script>
<Button disabled>Disabled</Button> Shadow
Colored elevation shadows for solid buttons.
<script>
import { Button } from '.';
</script>
<Button shadow>Primary</Button>
<Button shadow color="blue">Blue</Button>
<Button shadow color="green">Green</Button>
<Button shadow color="red">Red</Button> Ripple
Enable a click ripple effect with ripple. Prefer this only in interactive examples (client-side).
<script>
import { Button } from '.';
</script>
<Button ripple color="blue">Ripple</Button>
<Button ripple outline color="purple">Outline ripple</Button> Icons (leading / trailing)
Use leadingIcon and trailingIcon snippets for icon placement.
<script>
import { Button } from '.';
</script>
<Button>
{#snippet leadingIcon()}
<iconify-icon icon="bi:download"></iconify-icon>
{/snippet}
Download
</Button>
<Button color="green">
Next
{#snippet trailingIcon()}
<iconify-icon icon="bi:arrow-right"></iconify-icon>
{/snippet}
</Button> Composition notes
- With
href, the component renders an<a>; otherwise a<button type="button">(or customtag). - Inside
ButtonGroup, size defaults tosmand color defaults based on outline state. loadingforces disabled and appends aSpinner(spinnerPropscustomizes it).- Native button/anchor attributes (
type,target,rel,onclick, …) are forwarded.
Props
ButtonProps
| Prop | Type | Default | Description |
|---|---|---|---|
color | primary | dark | alternative | light | secondary | gray | red | orange | amber | yellow | lime | green | emerald | teal | cyan | sky | blue | indigo | violet | purple | fuchsia | pink | rose | primary | Theme color |
size | xs | sm | md | lg | xl | md | Padding / font size |
pill | boolean | false | Fully rounded |
outline | boolean | false | Border-only style |
shadow | boolean | false | Colored drop shadow |
disabled | boolean | — | Disable interaction |
loading | boolean | false | Shows spinner; disables button |
spinnerProps | Partial<SpinnerProps> | { size: '4', color: 'white' } | Spinner overrides when loading |
ripple | boolean | false | Click ripple effect |
href | string | — | Render as link |
tag | string | button | Custom element tag when not a link |
leadingIcon | Snippet | — | Content before children |
trailingIcon | Snippet | — | Content after children |
children | Snippet | — | Button label / content |
class | ClassValue | — | Extra classes |
…rest | button / anchor attrs | — | Forwarded to the root element |
GradientButtonProps
| Prop | Type | Default | Description |
|---|---|---|---|
color | blue | green | cyan | teal | lime | red | pink | purple | purpleToBlue | cyanToBlue | greenToBlue | purpleToPink | pinkToOrange | tealToLime | redToYellow | blue | Gradient preset |
size | xs | sm | md | lg | xl | — | Padding / font size |
pill | boolean | false | Fully rounded |
outline | boolean | — | Gradient border shell |
shadow | boolean | — | Drop shadow |
disabled | boolean | — | Disable interaction |
href | string | — | Render as link |
tag | string | — | Custom tag |
btnClass | ClassValue | — | Classes on inner button (outline mode) |
leadingIcon | Snippet | — | Content before children |
trailingIcon | Snippet | — | Content after children |
children | Snippet | — | Label / content |
class | ClassValue | — | Wrapper / root classes |
…rest | button / anchor attrs | — | Forwarded to the inner control |
Snippets
| Snippet | Components | Description |
|---|---|---|
leadingIcon | Button, GradientButton | Icon / node before the label |
trailingIcon | Button, GradientButton | Icon / node after the label |
children | Button, GradientButton | Main label content |