Skip to content

Image

Responsive image with aspect-ratio, object-fit, rounded corners, color and blur placeholder states, and a picture mode for art direction.

Import

import { Image } from "@hyzer-labs/ui"

Demo

Image + Lightbox

Image renders media; Lightbox handles viewing. Image has no click-to-view of its own. To add it, pass an Image into a Lightbox component's trigger snippet, or wire the lightboxGroup attachment over an Image grid you already render.
Aspect ratio 16/9 demo
<Image src="/photos/course.jpg" alt="Hole 7 fairway" aspectRatio="16/9" />

Props

NameTypeDefaultNote
srcstringRequired. Fallback in picture mode.
altstringRequired. Empty string for decorative.
sourcesImageSource[]Renders a <picture>: candidates in priority order — see ImageSource below. src remains the fallback and drives the load state.
widthnumber
heightnumber
loading'lazy' | 'eager''lazy'
aspectRatio'auto' | '1/1' | '4/3' | '16/9' | '21/9' | string'auto'
fit'cover' | 'contain' | 'fill' | 'none''cover'
roundedboolean | 'sm' | 'md' | 'lg' | 'full'falsetrue is shorthand for md.
placeholder'blur' | 'color' | 'none''none'
placeholderSrcstringLow-res image for placeholder="blur"; required in that mode.
placeholderColorstring'var(--hz-color-border)'
classstringMerged after the hz-image class.

ImageSource

NameTypeDefaultNote
srcsetstringRequired. Candidate URL(s) for this source.
typestringMIME type for format negotiation, e.g. 'image/avif'.
mediastringViewport media query for art direction, e.g. (min-width: 968px).
sizesstring

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-image

Data attributes

HookValuesStyles
data-state'loading' | 'loaded' | 'error'The load lifecycle. Read-only — the component owns it. Drives the placeholder crossfade and the error surface.
data-fit'cover' | 'contain' | 'fill' | 'none'object-fit on the inner img. Default cover.
data-roundedpresent | 'sm' | 'md' | 'lg' | 'full'Corner radius. Bare presence (from rounded={true}) means md.
data-aspect-ratio'auto' | '1/1' | '4/3' | '16/9' | '21/9' | any ratioMirrors the prop; the ratio itself lands as an inline style. The union is open — the listed values are documentation, not a limit.
data-placeholder'blur' | 'color'Absent when there is no placeholder — you cannot select [data-placeholder='none']. blur without placeholderSrc degrades to none.
data-loading'lazy' | 'eager'Mirrors the loading prop.
data-picturepresent in picture modePresent when sources are supplied.

Custom properties

HookValuesStyles
--hz-image-placeholder-blur<length> — default 20pxBlur radius on the low-res placeholder.
--hz-image-fade-duration<time> — default 0.3sPlaceholder crossfade duration. Read at both ends of the fade, so the two stay locked together.

Part classes

HookValuesStyles
.hz-image__imgchild elementThe real img. Note the BEM double underscore — Image and Video use it; the rest of the library uses a single dash.
.hz-image__placeholderchild elementThe decorative low-res image that fades out.
.hz-image__picturechild elementThe <picture> element. display: contents, so it adds no box.

Accessibility

Pass descriptive alt text for informative images. Pass alt='' for decorative images: the component then sets role='presentation' for you.

References: MDN: <img> · MDN: <picture>