Alert
Alerts provide contextual feedback messages for typical user actions with a handful of available and flexible alert messages.
Bootstrap Reference
Quick Start
Visual Examples & Use Cases
1. Dismissible Alerts
Allow users to close the alert. This is handled automatically by Bootstrap's JS via FastStrap's dismissible=True.
Code & Output
2. Rich Content
Alerts can contain headings, links, and multiple paragraphs.
Well done!
Aww yeah, you successfully read this important alert message.
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
3. Icons
Adding icons to alerts significantly improves user recognition of message status.
Practical Functionality
1. HTMX Integration (Auto-remove)
Commonly used for temporary notifications that should disappear after an HTMX update.
# Alert is removed from DOM after being seen (requires custom JS or HTMX trick)
Alert(
"Saved!",
variant="success",
hx_get="/clear_notification",
hx_trigger="load delay:3s" # Disappears after 3 seconds
)
Advanced Customization
1. CSS Variables
| CSS Variable | Description |
|---|---|
--bs-alert-bg |
Background color. |
--bs-alert-color |
Text color. |
--bs-alert-border-color |
Border color. |
--bs-alert-padding-x |
Padding. |
--bs-alert-link-color |
Color for <A> tags inside. |
Parameter Reference
| FastStrap Param | Type | Bootstrap Class | Description |
|---|---|---|---|
variant |
str |
.alert-{variant} |
Color theme. |
dismissible |
bool |
.alert-dismissible |
Adds a close button. |
icon |
str |
- | Bootstrap icon name to prepend. |
faststrap.components.feedback.alert.Alert(*children, variant=None, dismissible=None, heading=None, heading_cls=None, **kwargs)
Bootstrap Alert component for contextual feedback messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Alert content |
()
|
variant
|
VariantType | None
|
Bootstrap color variant |
None
|
dismissible
|
bool | None
|
Add close button to dismiss alert |
None
|
heading
|
Any | None
|
Optional heading text or element |
None
|
heading_cls
|
str | None
|
CSS class for heading |
None
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, hx-, data-, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with alert classes |