Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/compose_svelted/llms.txt
Use this file to discover all available pages before exploring further.
Image and Icon are the two media display primitives in Compose Svelted. Image renders any raster or vector graphic with configurable object-fit scaling behavior. Icon uses CSS masking to render SVG files as a monochrome shape tinted by any ColorToken or CSS color — the same technique used in Material 3 icon systems.
Image
Image wraps an <img> element inside a clipping <div>. Size and position are controlled by Modifier, and the fit behavior is set through ContentScale tokens.
Props
URL of the image to display. Use
painterResource() for assets bundled with your project, or any absolute/relative URL for external images.How the image is scaled and cropped within its bounds. See ContentScale values below.
Accessible
alt text for the rendered <img> element.Controls the size and shape of the image container. Use
Modifier.size(), Modifier.width(), or Modifier.height() to set explicit dimensions.ContentScale values
ContentScale is a constant object that maps semantic scaling names to CSS object-fit values (with two special fill modes handled in JavaScript):
| Token | CSS behavior | Use when |
|---|---|---|
ContentScale.Fit | object-fit: contain | Logo, illustration, or icon that must be fully visible |
ContentScale.Crop | object-fit: cover | Hero images, avatars, thumbnails |
ContentScale.FillBounds | object-fit: fill | Charts or diagrams that must match exact container |
ContentScale.Inside | object-fit: contain | Same as Fit; useful for explicit intent |
ContentScale.FillWidth | width 100%, height auto | Horizontal banner images |
ContentScale.FillHeight | height 100%, width auto | Vertical strip images |
ContentScale.None | object-fit: none | Pixel-art or images with fixed intrinsic sizes |
Basic example
Using painterResource
painterResource resolves a resource name to /assets/{resourceName}, mapping to the public/assets/ folder of your project.
Crop mode avatar
Icon
Icon renders a monochrome SVG icon using CSS masking. The SVG file is applied as a mask over a <div> whose background-color is set to the resolved tint color. This means the icon shape is always rendered as a solid, theme-aware color rather than the SVG’s own fill — making it trivial to adapt icons to any color role in the theme.
Props
URL of the SVG icon file. Use
painterResource(Res.raw(...)) for local SVG assets, or any public SVG URL.Icon color. Accepts a
ColorToken, a raw CSS color string, or undefined.- When
undefinedor omitted: falls back to theonBackgroundtheme token. - When a
ColorTokenstring (e.g."primary"): resolved through the active theme tovar(--md-sys-color-primary). - When a raw CSS hex/RGB/HSL string: used directly without theme resolution.
Controls the icon container’s size and layout. Use
Modifier.size(24) for standard 24 dp icons.How CSS masking works
Internally,Icon sets:
Basic example
Using a ColorToken
Using a raw CSS color
Using MDI SVG icon URLs
Material Design Icons (MDI) provides individual SVG files you can reference directly by URL:painterResource helper
painterResource and Res are utility helpers that mirror the Jetpack Compose painterResource pattern for loading local assets.
painterResource(resourceName)
public/assets/ directory of your project. painterResource prepends /assets/ so the browser resolves the file correctly from the web root.
Res namespace
Res provides sub-folder helpers that produce path segments you pass into painterResource:
| Helper | Subfolder | Intended for |
|---|---|---|
Res.raw(fileName) | raw/ | SVG icons, raw files |
Res.image(fileName) | img/ | PNG, JPEG, WebP images |
Res.values(fileName) | values/ | JSON data files |
Res.fonts(fileName) | fonts/ | Font files |
Example using Res helper
All files passed to
painterResource must be present in your project’s public/assets/ directory at build time. The helper is a pure string utility — it performs no existence check or bundling of its own.