This page as markdown: /media-image.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

MediaImage

Status: beta

An image that fills its box and falls back to GradientArt seeded by the item when it has no source or the source fails — Avatar's image-load tracking, for covers, thumbnails and product shots instead of faces.

Keywords: image, img, image fallback, broken image, cover art, album art, thumbnail, placeholder image, onError, missing image

Usage

Use MediaImage wherever content imagery may be missing or broken: a cover in a grid, a thumbnail in a row, a product shot. It fills the box it is given — an AspectBox for a cover, a sized and rounded box for a thumbnail — shows a quiet muted surface while the image loads, fades the image in once decoded, and paints GradientArt seeded by the item when there is no image to show, so a grid of missing covers still reads as distinct things. For a person use Avatar; for a whole tile with title and actions use MediaTile, which composes this.

Best practices

Props

Name Type Default Description
src string — Image URL. Omitted, empty or failing to load ⇒ the fallback shows.
alt string "" Alt text. Empty is decorative — right beside a visible title. When set and no image shows, it names the fallback instead.
seed string | number — Seeds the fallback art. Defaults to alt; pass the title or an id when alt is empty.
fallback ReactNode — Replaces the GradientArt fallback — a glyph or monogram. Fills the frame under the same clipping.
fit "cover" | "contain" "cover" cover crops to fill (artwork, photos); contain letterboxes on the muted surface (a logo, a product that must not be cropped).
position CSSProperties["objectPosition"] "center" Where the image sits in its frame — CSS object-position, the sibling of fit. Under cover it is the part the crop keeps ("50% 30%" for a face, "bottom" for a horizon); under contain it is the side the letterbox gives way to.
srcSet string — Responsive sources, passed to the <img>.
sizes string — The sizes attribute for srcSet.
loading "lazy" | "eager" "lazy" Native lazy loading. Use eager for the first row of a grid above the fold.
className string — Sizing and rounding when MediaImage is the box itself (size-14 rounded-md). Inside an AspectBox it already fills.

Variants

Tokens used

muted, art-1, art-2, art-3, art-4, art-5, art-6, art-ground

Motion

Accessibility

Related

Examples

Cover with fallback

import { AspectBox, MediaImage } from "@sableui/react"

<AspectBox ratio={1} className="rounded-md">
	<MediaImage src={album.cover} seed={album.title} />
</AspectBox>

No image yet

import { AspectBox, MediaImage } from "@sableui/react"

<AspectBox ratio={1} className="rounded-md">
	<MediaImage seed="Low tide, high noon" />
</AspectBox>

Row thumbnail

import { MediaImage } from "@sableui/react"

<MediaImage src={track.art} seed={track.title} className="size-12 shrink-0 rounded-sm" />

Logo, never cropped

import { AspectBox, MediaImage } from "@sableui/react"

<AspectBox ratio={16 / 9} className="rounded-lg">
	<MediaImage src={brand.logo} alt={brand.name} fit="contain" />
</AspectBox>

Crop focus per image

import { AspectBox, MediaImage } from "@sableui/react"

<AspectBox ratio={1} className="rounded-md">
	<MediaImage src={project.thumbnail} seed={project.title} position={project.focus ?? "center"} />
</AspectBox>