Forms

Button

Triggers an action, or navigates when given an href.

Installation

npx sinaui add button

Examples

Primary

The main action. Use one per view.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button>Borrow manuscript</Button>

Secondary

For the other actions beside the main one.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button variant="secondary">Add to reading list</Button>

Ghost

For quiet actions in toolbars, cards and lists.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button variant="ghost">Preview</Button>

Danger

Only for what can't be undone.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button variant="danger">Withdraw loan</Button>

Small

For tight spaces like table rows. On touch screens every size grows to at least 44px tall.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button size="sm" variant="secondary">Annotate</Button>

Large

For a page's main call to action.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button size="lg">Enter Bayt al-Hikma</Button>

Loading

The label is swapped for a spinner at the same width, so nothing around it moves. It keeps its name and focus, and ignores repeat clicks.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';

	let copying = $state(false);

	function transcribe() {
		copying = true;
		setTimeout(() => (copying = false), 1500);
	}
</script>

<Button loading={copying} onclick={transcribe}>Transcribe</Button>

With an icon

An icon before the label.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import Icon from '#lib/ui/Icon.svelte';
	import { Share08Icon } from '@hugeicons/core-free-icons';
</script>

<Button variant="secondary">
	<Icon icon={Share08Icon} /> Send to Córdoba
</Button>

Icon only

Square, and needs an aria-label.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import Icon from '#lib/ui/Icon.svelte';
	import { Share08Icon } from '@hugeicons/core-free-icons';
</script>

<Button square variant="secondary" aria-label="Share manuscript">
	<Icon icon={Share08Icon} />
</Button>

Disabled

Prefer explaining why something is unavailable; a disabled button can't be focused or explain itself.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
</script>

<Button disabled>Archived</Button>

With href it renders a real link, and variant="link" makes it look like one.

A link with a button style. Use it only when navigation is the page's main call to action.

Props

PropTypeDefault
variant'primary' | 'secondary' | 'ghost' | 'danger' | 'link''primary'
size'sm' | 'md' | 'lg''md'
loadingbooleanfalse
squarebooleanfalse
hrefstringrenders <a>
…restAny <button> or <a> attribute.

Accessibility

  • Renders <button type="button">, so it can't submit a form by accident. Pass type="submit" when it should.
  • While loading it uses aria-disabled, not disabled: it stays in the tab order, so screen reader users don't lose their place.
  • aria-pressed turns it into a toggle button with a visible pressed state.
KeyAction
Enter / SpaceActivates the button (links: Enter only).
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme