Button

Buttons allow users to take actions, and make choices, with a single tap.

Example

Variants

Use the variant prop to change the visual style of the button.

Icons

You can easily pass icons into the button via slot, and even use it as an icon-only button by using the iconOnly property.

Sizes

Buttons come in different sizes to fit your needs.

Disabled State

Use the disabled attribute to make a button inactive.

Ghost Button

Ghost button will make button background transparent, it is commonly used in colored background.

Danger Button

You can use the danger variant to mark button as danger status.

Block Button

The w-full class will make the button fit to its parent width.

Shapes

Buttons come in different shapes: rounded, pill, square, and circle.

Loading

A loading indicator can be added to a button by including a loader component.

Button Group

Use the ButtonGroup component to group multiple buttons together.

Orientation and Attachment

Vertical Attached

Horizontal Detached

Actions and Interactivity

Buttons support standard onclick events as well as declarative server actions via fetch attributes.

How to use

Import the button component and use it in your Astro files.

example.astro
---
import Button from '@/components/general/Button.astro';
---

<Button
  variant="primary"
  size="md"
  type="submit"
  onclick="alert('Hello!')"
>
  Submit Form
</Button>

API Reference

Property
Description
Type
Default

variant

The visual style variant of the button. 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger' 'primary'

iconOnly

Whether the button should only contain an icon. boolean false

size

The size of the button. 'sm' | 'md' | 'lg' 'md'

shape

The border radius shape of the button. 'rounded' | 'pill' | 'square' | 'circle' 'rounded'

action

URL for declarative fetch action. string -

method

HTTP method for the declarative action. 'get' | 'post' | 'put' | 'delete' 'get'

target

CSS selector for the target element to update. string -

swap

How to swap the content in the target element. 'inner' | 'outer' | 'prepend' | 'append' 'inner'

class

Additional CSS classes to apply. string -