Button
Buttons allow users to perform actions or navigate with a single click.
Installation
Add the button component to your project:
Usage
Primary Button
Loading preview...
Failed to load preview
Secondary Button
Loading preview...
Failed to load preview
Destructive Button
Loading preview...
Failed to load preview
Outline Button
Loading preview...
Failed to load preview
Ghost Button
Loading preview...
Failed to load preview
Sizes
Loading preview...
Failed to load preview
Loading preview...
Failed to load preview
With Icon
Loading preview...
Failed to load preview
Loading State
Loading preview...
Failed to load preview
Disabled
Loading preview...
Failed to load preview
Pill Shape
Loading preview...
Failed to load preview
Icon Button
Loading preview...
Failed to load preview
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant |
string |
primary |
Button style variant |
size |
string |
md |
Button size (xs, sm, md, lg, xl) |
type |
string |
button |
Button type (button, submit, reset) |
disabled |
boolean |
false |
Disable the button |
loading |
boolean |
false |
Show loading spinner |
icon |
string |
null |
Icon name (left side) |
iconRight |
string |
null |
Icon name (right side) |
iconOnly |
boolean |
false |
Icon-only button |
pill |
boolean |
false |
Rounded pill shape |
block |
boolean |
false |
Full width button |
href |
string |
null |
URL for link buttons |
action |
string |
null |
Livewire action to target |
Variants
default- Default stylingprimary- Primary action buttonsecondary- Secondary action buttonoutline- Outlined buttonghost- Minimal styling, hover onlydestructive- Dangerous action (delete, remove)
Sizes
sm- Small buttondefault- Default sizelg- Large buttonicon- Square button for icons
Examples
Submit Form
<form method="POST" action="/submit">
@csrf
<x-button type="submit">Submit</x-button>
</form>
Link Button
<a href="{{ route('dashboard') }}">
<x-button>Go to Dashboard</x-button>
</a>
Disabled State
<x-button disabled>
Disabled
</x-button>
Full Width
<x-button class="w-full">
Full Width Button
</x-button>
Customization
The button component uses Tailwind CSS classes. You can customize the appearance by modifying the component in your project:
@
@props([
'variant' => 'primary',
'size' => 'md',
// ... other props
])
@php
$variantClasses = match($variant) {
'primary' => 'bg-primary text-primary-foreground hover:bg-primary/90',
'secondary' => 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
// ... customize variants here
};
@endphp
<button {{ $attributes->class([$variantClasses]) }}>
{{ $slot }}
</button>
Accessibility
Buttons include proper ARIA attributes and keyboard support:
- Tab - Focus button
- Enter/Space - Activate button
- Disabled state - Automatically applied
Next Steps
- Explore Card component
- Learn about Input component
- View Modal component