SVG
Render SVG markup with optional sanitization.
Quick Start
Live Preview
Sanitization
Sanitization is enabled by default and uses bleach. Install the optional extras:
To allow raw SVG as-is, disable sanitization:
You can also pre-sanitize SVG strings with render_svg if you want to reuse output.
Theming
Use currentColor inside your SVG to inherit text color and automatically adapt to light and dark themes.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
svg |
str |
required | SVG markup. |
sanitize |
bool |
True |
Sanitize SVG with bleach. |
allowed_tags |
list[str] \| None |
None |
Override allowed SVG tags. |
allowed_attributes |
dict[str, list[str]] \| None |
None |
Override allowed SVG attributes. |
allowed_protocols |
list[str] \| None |
None |
Override allowed URL protocols. |
**kwargs |
Any |
Extra wrapper attributes. |
Security Notes
Only disable sanitization for trusted SVG markup. Treat user-provided SVG as untrusted input.
API Reference
faststrap.components.display.svg.render_svg(svg, *, sanitize=True, allowed_tags=None, allowed_attributes=None, allowed_protocols=None)
Render SVG markup with optional sanitization.
Source code in src/faststrap/components/display/svg.py
faststrap.components.display.svg.Svg(svg, *, sanitize=True, allowed_tags=None, allowed_attributes=None, allowed_protocols=None, **kwargs)
Render raw SVG into a styled container.