Mosmox UI
Current version
GitHubnpmjs.com
Content & Media

Image

Responsive images with fitting, aspect ratios, rounded corners, overlays, loading and fallback states.

Image wraps a native <img> with token-based presentation and resilient loading/error states.

Open the interactive Image examples on the component showcase →

Basic usage and fitting

alt remains required for accessible image content. fit maps to CSS object-fit: cover, contain, fill, none or scale-down.

<Image src="/hero.jpg" alt="A mountain landscape" />
<Image src="/logo.svg" alt="Company logo" fit="contain" />

Shape, ratio and overlay

radius accepts none, sm, default, lg or full. aspectRatio accepts a number or CSS ratio string such as 16 / 9. bordered adds a token border. overlay renders content over the image and can be positioned at top, center or bottom.

<Image src="/cover.jpg" alt="Cover" aspectRatio="16 / 9" radius="lg" overlay="View project" overlayPosition="bottom" />

Common aspect ratios include 1 / 1 for square images, 3 / 4 for portraits, 4 / 3 for standard landscape media and 16 / 9 for widescreen media. The ratio controls the wrapper; use style, className or a CSS width to control its size.

Hover and interaction

Images zoom smoothly by 1.08 on hover by default. Use hoverScale to control the zoom ratio and hoverDuration to control the transition speed in milliseconds. Set disableHover to remove the zoom. Providing onClick makes the image interactive: it receives a pointer cursor, focus styling and button-like Enter/Space keyboard activation.

<Image src="/cover.jpg" alt="Cover" aspectRatio="16 / 9" onClick={openPreview} />
<Image src="/cover.jpg" alt="Static cover" disableHover />
<Image src="/cover.jpg" alt="Strong hover" hoverScale={1.16} hoverDuration={420} />

Loading and fallback

The component shows a loader while the image is loading when showLoader is true (the default). When loading fails, fallback replaces the image. onLoad and onError are called in addition to the internal state handling.

If src is missing, the fallback content is rendered immediately. Native image attributes such as loading, decoding, srcSet, sizes, crossOrigin and referrerPolicy are passed to the underlying <img> element. className styles the wrapper; imageClassName styles the native image itself; style styles the wrapper and can set its width or height.

API Reference

PropValuesDefaultDescription
src, altnative image props—Image source and alternative text. alt should describe meaningful images; use an empty value for decorative images.
loading, decoding, srcSet, sizesnative image propsbrowser defaultsNative loading, decoding and responsive source settings.
fitcontain | cover | fill | none | scale-downcoverObject fitting mode.
radiusnone | sm | default | lg | fulldefaultCorner radius.
aspectRationumber | string—Wrapper aspect ratio.
borderedbooleanfalseAdds a border.
disableHoverbooleanfalseDisables the hover zoom.
hoverScalenumber1.08Scale applied to the image on hover. Values below 1 are normalized to 1.
hoverDurationnumber | string220 msCSS transition duration; numbers are interpreted as milliseconds.
onClickfunction—Makes the image interactive with pointer and keyboard activation.
overlayReactNode—Content layered above the image.
overlayPositiontop | center | bottomcenterOverlay alignment.
showLoaderbooleantrueShows loading indicator.
fallbackReactNodeImage unavailableError-state content.
classNamestring—Class for the wrapper.
imageClassNamestring—Class for the native image element.
styleCSSProperties—Inline styles for the wrapper, including dimensions.
onLoadimage load handler—Called after the image loads successfully.
onErrorimage error handler—Called when loading fails.