Image
An image that never shows an empty box or pops in. The frame keeps its size from ratio, a small blurred version of the picture shows at once, and the full image fades in over it once it has loaded.
Preview
Usage
When to use
- Show a photo, cover or illustration whose space must be kept while it loads.
- Show a blurred version of the picture first and fade to the full image once it loads.
When not to use
- A person, team or workspace picture. Use Avatar.
- Content whose layout is known but whose data is still loading. Use Skeleton.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| src | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| alt | Yes | Yes | Yes | |
| placeholderSrc | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| ratio | Yes | Yes | Yes | |
| radius | Yes | Yes | Yes | |
| placeholder | No | Yes | Yes | Only on iOS, Android. |
Variants
ratio
Width to height of the frame: 1:1, 4:3, 3:2, 16:9 or 21:9. Reserves the space before anything loads, so nothing moves. On web you can also pass a custom CSS aspect-ratio or set a height with className.
radius
Corner radius of the frame: auto follows the theme's radius-container token; full clips to a pill or circle (radius-full).
Examples
A cover image
The blurred copy shows at once, and the full image fades in over it.
Aspect ratios
Standard ratios keep the frame size before the image loads.
Round corners
auto follows the theme radius; full clips to a pill or circle.
Still loading
Without src yet, the blurred copy holds the frame.
Do and don't
Do
- Always reserve the space: ratio, an aspect class or a fixed height.
- Make placeholderSrc when the image is added, at build time or on upload, and inline it as a data URL.
- Serve the full image at the size it is shown (srcSet and sizes pass through to the image).
Don't
- Don't load placeholderSrc from a URL of its own: it would need a placeholder too.
- Don't use it for an avatar. Use Avatar, which shows initials until the photo loads.
- Don't put text over the image; its contrast is not checked.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| src | string | - | - | The full image. Until it is set and has loaded, the blurred copy (or the gray frame) shows. A new src shows the blurred copy again until the new image loads. Not generated for iOS and Android. |
| alt required | string | - | - | What the image shows, for screen readers. "" for a decorative image. |
| placeholderSrc | string | - | - | A small blurred version of the same image, best an inline data URL of a few hundred bytes (16 by 9 pixels is enough), made when the image is added (at build time or on upload), so it shows with the page and needs no request. Without it the frame shows the soft gray fill. Not generated for iOS and Android. |
| ratio | enum | 1:1 | 4:3 | 3:2 | 16:9 | 21:9 | 16:9 | Width to height of the frame: 1:1, 4:3, 3:2, 16:9 or 21:9. Reserves the space before anything loads, so nothing moves. On web you can also pass a custom CSS aspect-ratio or set a height with className. |
| radius | enum | auto | full | auto | Corner radius of the frame: auto follows the theme's radius-container token; full clips to a pill or circle (radius-full). |
| placeholder | node | - | - | Native only: a blurred placeholder view shown behind the image while it loads. Only on iOS, Android. |
Slots
| Name | Required | Description |
|---|---|---|
| image | yes | Native only: the image view you supply, drawn over the gray frame and clipped to the ratio and radius. |
Anatomy
| Part | Description |
|---|---|
| root | The frame: element corners, the soft gray fill, clips what is inside. ratio sets its aspect ratio, so the space is kept before anything loads. |
| blurred | placeholderSrc: a few pixels of the same picture, scaled to the frame and blurred, shown at once. |
| image | The full image on top. Transparent until it has loaded, then it fades in with duration-medium. |
Accessibility
Role: img
- alt is required by the type. Describe what the image shows; pass alt="" only for a decorative image.
- The blurred copy is hidden from screen readers (alt="" and aria-hidden), so the image is read once.
- No fade under prefers-reduced-motion: the full image appears in one step.
- A failed image shows the browser's broken-image box with the alt text, not an endless placeholder.
Install
npx werewolf-ui add imageRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.
