Grid System
Bootstrap's grid system uses a series of containers, rows, and columns to layout and align content. It's built with flexbox and is fully responsive. FastStrap mirrors this with Container, Row, and Col.
Bootstrap Reference
Quick Start
The grid follows a 12-column system.
Recommended Pattern
Prefer Row(..., cols=...) when you want evenly sized cards or repeated items,
and define the mobile layout first.
Row(
Card("Revenue"),
Card("Retention"),
Card("Pipeline"),
cols=1,
cols_md=2,
cols_lg=3,
gutter=3,
)
This makes the intended stack explicit:
- mobile: 1 item per row
- tablet: 2 items per row
- desktop: 3 items per row
Use custom cls="row ..." only when you specifically need raw Bootstrap row
behavior that is not already covered by Row() arguments.
Visual Examples & Use Cases
1. Responsive Breakpoints
You can specify different widths for different screen sizes (sm, md, lg, xl, xxl).
Code & Output
You can also control equal-width card grids at the row level:
2. Alignment & Spacing (Gutter)
Bootstrap's Flexbox utilities are available through the Row and Col arguments.
Code & Output
3. Container Fluid
By default, Container has a fixed width that changes at each breakpoint. Use fluid=True for a container that is always 100% wide.
Practical Functionality
1. Auto-width Columns
If you don't specify a width, Col will automatically share the space with other sibling columns.
2. Offsetting Columns
Move columns to the right using offset.
Parameter Reference
Container
| Param | Type | Bootstrap Class | Description |
|---|---|---|---|
fluid |
bool |
.container-fluid |
Spans the full width of the viewport. |
Row
| Param | Type | Bootstrap Class | Description |
|---|---|---|---|
cols |
int |
.row-cols-{val} |
Equal columns for the default/mobile layout. |
cols_sm |
int |
.row-cols-sm-{val} |
Equal columns from the sm breakpoint upward. |
cols_md |
int |
.row-cols-md-{val} |
Equal columns from the md breakpoint upward. |
cols_lg |
int |
.row-cols-lg-{val} |
Equal columns from the lg breakpoint upward. |
cols_xl |
int |
.row-cols-xl-{val} |
Equal columns from the xl breakpoint upward. |
cols_xxl |
int |
.row-cols-xxl-{val} |
Equal columns from the xxl breakpoint upward. |
gutter |
int |
.g-{val} |
Spacing between columns (0-5). |
gx |
int |
.gx-{val} |
Horizontal gutter only. |
gy |
int |
.gy-{val} |
Vertical gutter only. |
justify |
str |
.justify-content-{val} |
Alignment: start, center, end, around, between. |
align |
str |
.align-items-{val} |
Vertical alignment: start, center, end. |
Col
| Param | Type | Bootstrap Class | Description |
|---|---|---|---|
span |
int \| bool |
.col / .col-{val} |
Auto width when True, or a specific mobile/default span (1-12). |
sm |
int |
.col-sm-{val} |
Width from the sm breakpoint upward. |
md |
int |
.col-md-{val} |
Width from the md breakpoint upward. |
lg |
int |
.col-lg-{val} |
Width from the lg breakpoint upward. |
xl |
int |
.col-xl-{val} |
Width from the xl breakpoint upward. |
xxl |
int |
.col-xxl-{val} |
Width from the xxl breakpoint upward. |
offset |
int |
.offset-{val} |
Prepend empty columns. |
offset_sm |
int |
.offset-sm-{val} |
Offset from the sm breakpoint upward. |
offset_md |
int |
.offset-md-{val} |
Offset from the md breakpoint upward. |
offset_lg |
int |
.offset-lg-{val} |
Offset from the lg breakpoint upward. |
offset_xl |
int |
.offset-xl-{val} |
Offset from the xl breakpoint upward. |
offset_xxl |
int |
.offset-xxl-{val} |
Offset from the xxl breakpoint upward. |
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 | |