Figure
The Figure component is used for displaying content—like images—with an optional caption. It provides consistent padding and styling for image-based content blocks.
Bootstrap Reference
Quick Start
Visual Examples & Use Cases
1. Alignment
Captions can be aligned to the start (left), center, or end (right).
Code & Output
2. Styling (Thumbnail & Rounded)
Wrap the image in a thumbnail border or round the corners.
Parameter Reference
| FastStrap Param | Type | Bootstrap Class | Description |
|---|---|---|---|
src |
str |
src="..." |
Image URL. |
alt |
str |
alt="..." |
Alt text for accessibility. |
caption |
str |
.figure-caption |
Text to display below image. |
align |
str |
.text-{align} |
Caption alignment: start, center, end. |
fluid |
bool |
.img-fluid |
Makes image responsive (full width). |
rounded |
bool |
.rounded |
Rounds image corners. |
thumbnail |
bool |
.img-thumbnail |
Adds a 1px border with padding. |
faststrap.components.display.figure.Figure(src, caption=None, alt='', size=None, align=None, fluid=True, rounded=True, thumbnail=False, img_cls='', caption_cls='', **kwargs)
Bootstrap Figure component.
Displays an image with an optional caption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Image source URL |
required |
caption
|
str | Any | None
|
Caption text or component (optional) |
None
|
alt
|
str
|
Image alternative text |
''
|
size
|
str | None
|
Width of the figure (e.g. "25%", "50%") - adds w-* class if matches standard sizes, else style |
None
|
align
|
str | None
|
Caption alignment ("start", "center", "end") |
None
|
fluid
|
bool
|
Make image responsive (img-fluid) |
True
|
rounded
|
bool
|
Add rounded corners |
True
|
thumbnail
|
bool
|
Style image as thumbnail |
False
|
img_cls
|
str
|
Additional classes for image |
''
|
caption_cls
|
str
|
Additional classes for caption |
''
|
**kwargs
|
Any
|
Additional HTML attributes for the figure element |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
FastHTML Figure element |
Example
Figure("image.jpg", caption="A nice view")
Figure("avatar.png", size="50%", rounded=True, align="center")