Grid
The Container, Row, and Col components implement the Bootstrap 5 responsive grid system.
Quick Start
Usage Scenarios
Fixed-Width Container
Fluid Container
Fluid Until Breakpoint
Responsive Row
Row(
Col("A", span=12, cols_md=6, cols_lg=4),
Col("B", span=12, cols_md=6, cols_lg=4),
Col("C", span=12, cols_md=6, cols_lg=4),
)
Column with Offset
Responsive Column Sizing
Parameter Reference
Container
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
Required | Container content |
fluid |
bool \| str |
False |
Fluid container type (True/"fluid" for full-width, "sm"/"md"/"lg"/"xl"/"xxl" for fluid until breakpoint) |
**kwargs |
Any |
- | Additional HTML attributes |
Row
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
Required | Row content (typically Col components) |
cols |
int \| None |
None |
Number of columns for all breakpoints (1-12) |
cols_sm |
int \| None |
None |
Columns for small devices (≥576px) |
cols_md |
int \| None |
None |
Columns for medium devices (≥768px) |
cols_lg |
int \| None |
None |
Columns for large devices (≥992px) |
cols_xl |
int \| None |
None |
Columns for extra large devices (≥1200px) |
cols_xxl |
int \| None |
None |
Columns for extra extra large devices (≥1400px) |
**kwargs |
Any |
- | Additional HTML attributes |
Col
| Parameter | Type | Default | Description |
|---|---|---|---|
*children |
Any |
Required | Column content |
span |
int \| bool |
True |
Column span (1-12) or True for auto-width |
sm |
int \| None |
None |
Span for small devices (≥576px) |
md |
int \| None |
None |
Span for medium devices (≥768px) |
lg |
int \| None |
None |
Span for large devices (≥992px) |
xl |
int \| None |
None |
Span for extra large devices (≥1200px) |
xxl |
int \| None |
None |
Span for extra extra large devices (≥1400px) |
offset |
int \| None |
None |
Offset columns (0-11) |
offset_sm |
int \| None |
None |
Offset for small devices |
offset_md |
int \| None |
None |
Offset for medium devices |
offset_lg |
int \| None |
None |
Offset for large devices |
offset_xl |
int \| None |
None |
Offset for extra large devices |
offset_xxl |
int \| None |
None |
Offset for extra extra large devices |
**kwargs |
Any |
- | Additional HTML attributes |
Accessibility
- Grid is purely structural and does not add accessibility barriers.
- Content within columns maintains proper heading hierarchy.
API Reference
faststrap.components.layout.grid.Container(*children, fluid=False, **kwargs)
Bootstrap Container for responsive fixed-width or fluid layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Container content |
()
|
fluid
|
ContainerType | bool
|
Fluid container type: - False: Fixed-width responsive container (default) - True/"fluid": Full-width container - "sm"/"md"/"lg"/"xl"/"xxl": Fluid until breakpoint |
False
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, hx-, data-, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with container classes |
Examples:
Fixed-width responsive:
Full-width fluid:
Fluid until large breakpoint:
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/layout/containers/
Source code in src/faststrap/components/layout/grid.py
faststrap.components.layout.grid.Row(*children, cols=None, cols_sm=None, cols_md=None, cols_lg=None, cols_xl=None, cols_xxl=None, **kwargs)
Bootstrap Row for grid layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Row content (typically Col components) |
()
|
cols
|
int | None
|
Number of columns for all breakpoints (1-12) |
None
|
cols_sm
|
int | None
|
Columns for small devices (≥576px) |
None
|
cols_md
|
int | None
|
Columns for medium devices (≥768px) |
None
|
cols_lg
|
int | None
|
Columns for large devices (≥992px) |
None
|
cols_xl
|
int | None
|
Columns for extra large devices (≥1200px) |
None
|
cols_xxl
|
int | None
|
Columns for extra extra large devices (≥1400px) |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with row classes |
Examples:
Basic row:
Auto-layout 3 equal columns:
Responsive columns:
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/layout/grid/
Source code in src/faststrap/components/layout/grid.py
faststrap.components.layout.grid.Col(*children, span=True, sm=None, md=None, lg=None, xl=None, xxl=None, offset=None, offset_sm=None, offset_md=None, offset_lg=None, offset_xl=None, offset_xxl=None, **kwargs)
Bootstrap Column for grid layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
Column content |
()
|
span
|
int | bool
|
Column span (1-12) or True for auto-width |
True
|
sm
|
int | None
|
Span for small devices (≥576px) |
None
|
md
|
int | None
|
Span for medium devices (≥768px) |
None
|
lg
|
int | None
|
Span for large devices (≥992px) |
None
|
xl
|
int | None
|
Span for extra large devices (≥1200px) |
None
|
xxl
|
int | None
|
Span for extra extra large devices (≥1400px) |
None
|
offset
|
int | None
|
Offset columns (0-11) |
None
|
offset_sm
|
int | None
|
Offset for small devices |
None
|
offset_md
|
int | None
|
Offset for medium devices |
None
|
offset_lg
|
int | None
|
Offset for large devices |
None
|
offset_xl
|
int | None
|
Offset for extra large devices |
None
|
offset_xxl
|
int | None
|
Offset for extra extra large devices |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with column classes |
Examples:
Auto-width column:
Fixed span:
Responsive sizing:
With offset:
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/layout/columns/
Source code in src/faststrap/components/layout/grid.py
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 223 224 225 226 227 228 229 230 231 232 233 234 | |