Web · Components
Image
Image that manages its own loading, error and placeholder states.
3 exports
Live example
Preview

Code
Events
- Events appear here when you interact with the preview.
An image filling the box in a card (fill) and a custom error view

Aegean cove
Custom error view
Import
Image that manages its own loading, error and placeholder states. Can be used anywhere; Gallery thumbnails are rendered with it too.
- While loading: a shimmering skeleton, the image's dominant color or a small blurred image (
placeholder); appears smoothly once loaded. - No layout shift: with
width+height,ratioorfillthe box reserves space before the image loads. - Error: an icon and "Try again"; it retries automatically when the connection comes back.
- Loads lazily (
loading="lazy");priorityfor an image on the first screen. - Next.js: The component doesn't depend on
next/image. WhenoptimizeImagesis enabled in the@yasinsensoy/web/nextprovider, allImages render withnext/image(resizing, WebP/AVIF). For another CDN component use theimageprop ofUIProvider.
It is a client component; it can be used with props from a server component.
Examples
ImageClassNames
interfaceClasses added to the parts of Image.
| Name | Type | Description |
|---|---|---|
image? | string | The <img> element itself. |
placeholder? | string | Placeholder (color, blurred thumbnail or shimmer). |
fallback? | string | Error view. |
ImageProps
interfaceProps of the Image component.
Extends: Omit<ComponentProps<"img">, "src" | "alt" | "width" | "height" | "placeholder" | "onLoad" | "onError" | "ref">
| Name | Type | Default | Description |
|---|---|---|---|
src | string | Image URL. | |
alt | string | Alternative text. Pass "" for a decorative image. | |
width? | number | Original width (px). Given together with height, the box reserves space at the right ratio before the image loads (the page doesn't shift); it shrinks if it doesn't fit the width. | |
height? | number | Original height (px). See width. | |
ratio? | number | Box ratio (width / height, e.g. 16 / 9). If given, the box becomes full width and reserves space at this ratio. | |
fill? | boolean | false | Fill the positioned (relative) container entirely. For cards, backgrounds and galleries. |
fit? | "cover" | "contain" | "fill" | "none" | "scale-down" | "cover" | How the image fits the box (object-fit). |
placeholder? | string | "shimmer" | Shown until it loads: a color ("#8a9bb0", the image's dominant color), a small blurred image (data:image/... or a URL), "shimmer" a shimmering skeleton, or "none". |
appear? | "fade" | "scale" | "none" | "fade" | Appearance on load: "fade", "scale" (growing slightly) or "none". |
fallback? | ReactNode | ((retry: () => void) => ReactNode) | Content shown if it fails to load. If omitted, an icon, "Image failed to load" and a "Try again" button appear. With a function it receives the retry function. null shows nothing. | |
priority? | boolean | false | The page's first visible image (e.g. a cover, product image): doesn't load lazily, loads with priority. Keep it to one or two images per page. |
unoptimized? | boolean | false | Skip the image component given to UIProvider (e.g. next/image) and use a plain <img>. For blob: previews and external SVGs. |
onLoad? | (image: HTMLImageElement) => void | On load; with the image itself (for measurements like naturalWidth). | |
onError? | () => void | On failure. | |
imageRef? | Ref<HTMLImageElement> | Access to the <img> element. | |
className? | string | Classes added to the box (e.g. rounded-lg). | |
classNames? | ImageClassNames | Classes added to the parts. See ImageClassNames. | |
style? | CSSProperties | Style of the box. | |
effect? | EffectProp | Effect or effects of the image box (e.g. "shine", ["tilt", "glow"]). If omitted, UIProvider appearance.defaults.image.effect. See BuiltinEffect. |