Toast
Toasts are lightweight, non-blocking notifications. They are designed to mimic the push notifications popularized by mobile and desktop operating systems.
Bootstrap Reference
Quick Start
In FastStrap, we use SimpleToast for the most common case: a simple text message with a variant color.
Visual Examples & Use Cases
1. SimpleToast Variants
Standard colors to communicate status.
Code & Output
2. Full Control (Standard Toast)
For rich content, headers, and custom timing, use the base Toast component.
Code & Output
3. Toast Container
Toasts are often grouped. FastStrap handles the ToastContainer logic to ensure they stack correctly in the corner of the screen.
from faststrap import ToastContainer, add_bootstrap
# 1. Add container to your main layout
app_layout = [
MainView(),
ToastContainer(position="bottom-end") # Global container
]
Practical Functionality
1. Triggering Toasts via HTMX
The most common implementation is to return a Toast as part of an HTMX response (using hx-swap="beforeend" targetting the Toast Container).
@app.route("/add_item")
def add_item():
# ... logic ...
return SimpleToast("Item Added", variant="success") # Appends to existing list
Parameter Reference
| FastStrap Param | Type | Bootstrap Attribute | Description |
|---|---|---|---|
title |
Any |
.toast-header |
Optional header element/text. |
autohide |
bool |
data-bs-autohide |
If True, closes automatically. |
delay |
int |
data-bs-delay |
Duration in milliseconds before closing. |
duration (SimpleToast) |
int |
CSS animation delay | Duration in milliseconds before fade out. |
position |
str |
- | Location: top-end, bottom-start, etc. |
radius |
str \| None |
None |
Radius token (sm, md, lg, none, pill); None keeps the default rounding. |
header_cls / body_cls / close_button_cls (Toast) |
str |
"" |
Slot class hooks for the header row, body, and dismiss button. |
body_cls (SimpleToast) |
str |
"" |
Extra classes for the toast body. |
Toast Placements
ToastContainer supports 13 placement positions via the position parameter or the ToastPlacement helper:
| Position Value | Screen Location | Use Case |
|---|---|---|
top-left |
Top-left corner | Desktop admin tools |
top-center |
Top center | Desktop notifications |
top-right |
Top-right corner | Classic desktop notifications |
bottom-left |
Bottom-left corner | Mobile-friendly (left-handed) |
bottom-center |
Bottom center | Mobile-friendly centered |
bottom-right (default) |
Bottom-right corner | Mobile-friendly, most common |
top-start |
Top-left (RTL-aware) | RTL language support |
top-end |
Top-right (RTL-aware) | RTL language support |
bottom-start |
Bottom-left (RTL-aware) | RTL language support |
bottom-end |
Bottom-right (RTL-aware) | RTL language support |
middle-start |
Middle-left (RTL-aware) | Centered vertical alerts |
middle-center |
Dead center | Modal-like toasts |
middle-end |
Middle-right (RTL-aware) | Centered vertical alerts |
from faststrap import ToastContainer, ToastPlacement
# Using a string
ToastContainer(position="bottom-right")
# Using the typed helper
ToastContainer(
position=ToastPlacement(
position="bottom-right",
offset=16, # pixels from edge
gutter=8, # spacing between toasts
),
)
The offset and gutter parameters control spacing: offset is the distance from the screen edge, and gutter is the gap between stacked toasts.
Multiple toasts in the same container stack vertically with the newest toast appearing closest to the center (configurable via stack_order).
faststrap.components.feedback.modern_toast.ToastPlacement
dataclass
Source code in src/faststrap/components/feedback/modern_toast.py
Multiple ToastContainers are supported: pass a distinct container_id per container, or container_id=None for an auto-generated id.
JavaScript Requirement
The Toast component requires Bootstrap's JavaScript plugin. FastStrap automatically initializes Bootstrap Toasts via faststrap-init.js when add_bootstrap(app, components=[Toast, ...]) is called, or when JS is always included.
faststrap.components.feedback.toast.SimpleToast(*children, title=None, variant=UNSET, duration=UNSET, position=UNSET, radius=None, body_cls='', **kwargs)
Simple Toast component that works without JavaScript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Toast body content. |
()
|
title
|
str | None
|
Optional heading rendered above the body. |
None
|
variant
|
VariantType | None
|
Bootstrap alert variant color. |
UNSET
|
duration
|
int | None
|
Auto-fade delay in milliseconds. |
UNSET
|
position
|
ToastPositionType | None
|
Fixed screen position. |
UNSET
|
radius
|
str | None
|
Radius token ( |
None
|
body_cls
|
str
|
Extra classes for the toast body. |
''
|
**kwargs
|
Any
|
Additional HTML attributes. |
{}
|
Source code in src/faststrap/components/feedback/toast.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 | |
faststrap.components.feedback.toast.Toast(*children, title=None, variant=UNSET, autohide=UNSET, delay=UNSET, animation=UNSET, radius=None, header_cls='', body_cls='', close_button_cls='', **kwargs)
Bootstrap Toast component for temporary notifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Toast body content. |
()
|
title
|
str | None
|
Optional header text; renders the |
None
|
variant
|
VariantType | None
|
Bootstrap color variant applied as |
UNSET
|
autohide
|
bool | None
|
Whether Bootstrap auto-hides the toast. |
UNSET
|
delay
|
int | None
|
Auto-hide delay in milliseconds. |
UNSET
|
animation
|
bool | None
|
Whether Bootstrap animates show/hide. |
UNSET
|
radius
|
str | None
|
Radius token ( |
None
|
header_cls
|
str
|
Extra classes for the header row. |
''
|
body_cls
|
str
|
Extra classes for the body row. |
''
|
close_button_cls
|
str
|
Extra classes for the close button. |
''
|
**kwargs
|
Any
|
Additional HTML attributes. |
{}
|
Source code in src/faststrap/components/feedback/toast.py
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 222 | |
faststrap.components.feedback.toast.ToastContainer(*toasts, position=UNSET, container_id='toast-container', **kwargs)
Container for positioning toasts on the page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*toasts
|
Any
|
Toast components to place inside the container. |
()
|
position
|
ToastPositionType | None
|
Fixed screen position of the container. |
UNSET
|
container_id
|
str | None
|
DOM id for HTMX targeting; pass |
'toast-container'
|
**kwargs
|
Any
|
Additional HTML attributes. |
{}
|