Layout Primitives
Stack, Cluster, and Center are zero-JS flexbox layout primitives that cover the most common layout patterns in web applications. They use Bootstrap utility classes under the hood, so they are lightweight, responsive, and familiar.
Bootstrap Reference
Quick Start
from faststrap import Stack, Cluster, Center, Button
# Vertical stack with gap
Stack(
"Profile",
"Billing",
"Security",
gap=3,
)
# Horizontal action row
Cluster(
Button("Save", variant="primary"),
Button("Cancel", variant="secondary", outline=True),
justify="end",
)
# Centered content
Center(
"Nothing selected yet",
min_height="40vh",
max_width="32rem",
)
Visual Examples & Use Cases
1. Stack (Vertical Layout)
2. Cluster (Horizontal Layout)
Live Preview
3. Center (Centered Content)
Live Preview
Nothing selected yet
4. Nested Layouts
Live Preview
Item 1
Item 2
Practical Functionality
1. Sidebar Navigation
Stack(
NavbarItem("Dashboard", href="/", icon="speedometer2"),
NavbarItem("Users", href="/users", icon="people"),
NavbarItem("Settings", href="/settings", icon="gear"),
gap=1,
)
2. Action Bar with HTMX
Cluster(
Button("Save", variant="primary", hx_post="/save", hx_target="#form", hx_swap="outerHTML"),
Button("Cancel", variant="secondary", hx_get="/cancel", hx_target="#form"),
justify="between",
)
3. Empty State
Center(
EmptyState(
"No data yet",
description="Create your first item to get started.",
icon="inbox",
),
min_height="60vh",
)
Parameter Reference
Stack
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
required | Stacked content. |
gap |
int |
2 |
Bootstrap gap utility suffix (0–5). |
align |
str \| None |
None |
Bootstrap align-items-* class. |
justify |
str \| None |
None |
Bootstrap justify-content-* class. |
**kwargs |
Any |
{} |
Additional HTML attributes. |
Cluster
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
required | Clustered content. |
gap |
int |
2 |
Bootstrap gap utility suffix (0–5). |
align |
str \| None |
None |
Bootstrap align-items-* class. |
justify |
str \| None |
None |
Bootstrap justify-content-* class. |
wrap |
bool |
True |
Allow children to wrap. |
**kwargs |
Any |
{} |
Additional HTML attributes. |
Center
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
required | Centered content. |
min_height |
str |
"100vh" |
Minimum container height. |
max_width |
str |
"100%" |
Maximum content width. |
text_center |
bool |
True |
Apply text-center class. |
**kwargs |
Any |
{} |
Additional HTML attributes. |
API Reference
faststrap.components.layout.primitives.Stack(*children, gap=UNSET, align=UNSET, justify=UNSET, **kwargs)
Render a vertical flex stack with a Bootstrap gap scale.
Source code in src/faststrap/components/layout/primitives.py
faststrap.components.layout.primitives.Cluster(*children, gap=UNSET, align=UNSET, justify=UNSET, wrap=UNSET, **kwargs)
Render a horizontal wrapping cluster for action rows and chips.
Source code in src/faststrap/components/layout/primitives.py
faststrap.components.layout.primitives.Center(*children, min_height=UNSET, max_width=UNSET, text_center=UNSET, **kwargs)
Render content centered on both axes.