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.
Visual Examples & Use Cases
1. Responsive Breakpoints
You can specify different widths for different screen sizes (sm, md, lg, xl, xxl).
Code & Output
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 |
|---|---|---|---|
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 |
|---|---|---|---|
width |
int |
.col-{val} |
Mobile/default width (1-12). |
sm |
int |
.col-sm-{val} |
Tablet width. |
md |
int |
.col-md-{val} |
Desktop width. |
lg |
int |
.col-lg-{val} |
Large screen width. |
offset |
int |
.offset-{val} |
Prepend empty columns. |
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 |
Example
Fixed-width responsive:
Container(H1("Welcome"), P("Content"))
Full-width fluid:
Container(Row(...), fluid=True)
Fluid until large breakpoint:
Container(content, fluid="lg")
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 |
Example
Basic row:
Row(Col("Column 1"), Col("Column 2"))
Auto-layout 3 equal columns:
Row(Col(...), Col(...), Col(...), cols=3)
Responsive columns:
Row(children, cols=1, cols_md=2, cols_lg=3)
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 |
Example
Auto-width column:
Col("Auto width")
Fixed span:
Col("Half width", span=6)
Responsive sizing:
Col("Content", span=12, md=6, lg=4)
With offset:
Col("Offset by 3", span=6, offset=3)
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 | |