Button
The Button component wraps standard HTML <button> or <a> elements with Bootstrap styling, loading states, and icon support.
Quick Start
Usage Scenarios
Variants
Button("Primary", variant="primary")
Button("Secondary", variant="secondary")
Button("Success", variant="success")
Button("Danger", variant="danger")
Button("Warning", variant="warning")
Button("Info", variant="info")
Button("Light", variant="light")
Button("Dark", variant="dark")
Button("Link", variant="link")
Outline Style
Button("Delete", variant="danger", outline=True)
Button("Save Draft", variant="primary", outline=True)
Sizes
Button("Join Now!", size="lg", variant="primary")
Button("Default", variant="secondary")
Button("Details", size="sm", variant="info")
Full Width
Anchor Tag
Icons
Button("Save", icon="check-circle", variant="success")
Button("Next Step", icon="arrow-right", icon_pos="end", variant="primary")
Loading State
Parameter Reference
| FastStrap Param | Type | Bootstrap Class / Attribute | Description |
|---|---|---|---|
variant |
str |
.btn-{variant} |
Color theme. Options: primary, secondary, success, danger, warning, info, light, dark, link. |
outline |
bool |
.btn-outline-{variant} |
If True, renders outline style instead of solid fill. |
size |
str |
.btn-{size} |
Size of button. Options: sm (Small), lg (Large). Default is Medium. |
full_width |
bool |
.w-100 |
Makes button span full width of parent. |
pill |
bool |
.rounded-pill |
Gives button fully rounded corners. |
as_ |
str |
<tag> |
Tag to render. Default button. Use a for links. |
href |
str |
href="..." |
URL destination (requires as_="a"). |
disabled |
bool |
disabled / .disabled |
Disables interactivity and applies disabled styling. |
active |
bool |
.active |
Forces the button to appear in a "pressed" state. |
icon |
str |
<i class="bi bi-{icon}"> |
Adds a Bootstrap Icon (e.g., "check", "house"). |
icon_pos |
str |
- | Position of icon: start (default) or end. |
spinner |
bool |
.spinner-border |
Controls whether loading=True renders a spinner. |
loading |
bool |
- | Helper that enables spinner and disabled state together. |
loading_text |
str |
- | Text to display when loading=True. |
css_vars |
dict |
style="--var: val" |
Dict of CSS variables to apply inline. |
Accessibility
- Buttons default to
type="button"to prevent accidental form submission. - When rendered as an anchor (
as_="a"),role="button"is added automatically. - Loading state sets
aria-busy="true". - Active state sets
aria-pressed="true". - Icons and spinners use
aria-hidden="true".
API Reference
faststrap.components.forms.button.Button(*children, as_='button', variant=UNSET, size=UNSET, outline=UNSET, disabled=UNSET, loading=False, spinner=True, loading_text=None, icon=None, icon_pos='start', icon_cls=None, spinner_pos='start', spinner_cls=None, full_width=UNSET, active=UNSET, pill=UNSET, css_vars=None, style=None, **kwargs)
Bootstrap Button component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Button content (text, elements) |
()
|
as_
|
Literal['button', 'a']
|
Render as 'button' or 'a' tag (default: 'button') |
'button'
|
variant
|
VariantType | None
|
Bootstrap color variant |
UNSET
|
size
|
SizeType | None
|
Button size (sm, lg) |
UNSET
|
outline
|
bool | None
|
Use outline style |
UNSET
|
disabled
|
bool | None
|
Disable button |
UNSET
|
loading
|
bool
|
Show loading spinner and disable |
False
|
spinner
|
bool
|
Show spinner when loading |
True
|
loading_text
|
str | None
|
Text to show when loading |
None
|
icon
|
str | None
|
Bootstrap icon name |
None
|
icon_pos
|
Literal['start', 'end']
|
Icon position ('start' or 'end') |
'start'
|
icon_cls
|
str | None
|
Custom classes for icon |
None
|
spinner_pos
|
Literal['start', 'end']
|
Spinner position ('start' or 'end') |
'start'
|
spinner_cls
|
str | None
|
Custom classes for spinner |
None
|
full_width
|
bool | None
|
Make button 100% width. Note: Can also be achieved via |
UNSET
|
active
|
bool | None
|
Set active state. Note: Can also be achieved via |
UNSET
|
pill
|
bool | None
|
Use rounded-pill style. Note: Can also be achieved via |
UNSET
|
css_vars
|
dict[str, Any] | None
|
Custom CSS variables dictionary |
None
|
style
|
dict[str, Any] | str | None
|
Custom inline style |
None
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, hx-, data-, etc.) |
{}
|
Source code in src/faststrap/components/forms/button.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
faststrap.components.forms.button.CloseButton(*children, white=False, aria_label='Close', **kwargs)
Bootstrap close button helper.
This is used by components like Alerts, Modals, and Drawers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Optional children. Bootstrap typically uses an empty button. |
()
|
white
|
bool
|
Use white close icon variant (useful on dark backgrounds) |
False
|
aria_label
|
str
|
Accessible label |
'Close'
|
**kwargs
|
Any
|
Additional HTML attributes (cls, data-, hx-, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Button
|
FastHTML Button element |