Image
Responsive image component with Bootstrap utilities.
Basic Usage
from faststrap import Image
# Responsive image
Image(src="/photos/landscape.jpg", alt="Beautiful landscape", fluid=True)
# Thumbnail
Image(src="/profile.jpg", alt="Profile", thumbnail=True)
# Circular
Image(src="/avatar.jpg", alt="Avatar", rounded_circle=True)
API Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
src |
str | Required | Image source URL |
alt |
str \| None |
None |
Alternative text. |
fluid |
bool \| None |
False |
Add .img-fluid for responsive sizing. |
thumbnail |
bool \| None |
False |
Add thumbnail border/padding. |
rounded |
bool \| None |
False |
Round corners. |
rounded_circle |
bool \| None |
False |
Make image circular with .rounded-circle. |
align |
str \| None |
None |
Alignment: "start", "center", or "end". |
width |
str \| int \| None |
None |
Image width. Integers are emitted as pixel values. |
height |
str \| int \| None |
None |
Image height. Integers are emitted as pixel values. |
loading |
"lazy" \| "eager" \| None |
None |
Native browser image loading hint. |
**kwargs |
Any | - | Additional HTML attributes |
Examples
Responsive Fluid Image
Profile Avatar
Image(
src="/users/john.jpg",
alt="John Doe",
rounded_circle=True,
style={"width": "100px", "height": "100px"}
)
Thumbnail Gallery
Row(
Col(Image(src="/gallery/1.jpg", thumbnail=True), md=3),
Col(Image(src="/gallery/2.jpg", thumbnail=True), md=3),
Col(Image(src="/gallery/3.jpg", thumbnail=True), md=3),
Col(Image(src="/gallery/4.jpg", thumbnail=True), md=3)
)
Centered Image
Accessibility
- Always provide meaningful
alttext - Use empty
alt=""for decorative images - Ensure sufficient color contrast for overlaid text
See Also
API Reference
faststrap.components.display.image.Image(src, alt=None, fluid=UNSET, thumbnail=UNSET, rounded=UNSET, rounded_circle=UNSET, align=UNSET, width=None, height=None, loading=UNSET, **kwargs)
Bootstrap Image component with responsive utilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Image source URL (required) |
required |
alt
|
str | None
|
Alternative text for accessibility |
None
|
fluid
|
bool | None
|
Make image responsive (max-width: 100%, height: auto) |
UNSET
|
thumbnail
|
bool | None
|
Add thumbnail styling (border, padding, rounded) |
UNSET
|
rounded
|
bool | None
|
Add rounded corners |
UNSET
|
rounded_circle
|
bool | None
|
Make image circular |
UNSET
|
align
|
AlignType | None
|
Float alignment (start=left, end=right, center) |
UNSET
|
width
|
str | int | None
|
Image width (CSS value or pixels) |
None
|
height
|
str | int | None
|
Image height (CSS value or pixels) |
None
|
loading
|
Literal['lazy', 'eager'] | None
|
Native lazy loading (lazy or eager) |
UNSET
|
**kwargs
|
Any
|
Additional HTML attributes (cls, id, style, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Img
|
FastHTML Img element with Bootstrap image classes |
Examples:
Basic responsive image:
Thumbnail with rounded corners:
Aligned image:
Lazy loading:
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/content/images/
Source code in src/faststrap/components/display/image.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |