Image

Responsive image component with aspect ratio control, loading states, and error fallbacks. Handles image display with consistent styling.

Setup

import { Image } from '@fragments-sdk/ui';

Examples

Default

Basic image display

Loading preview...

Aspect Ratios

Different aspect ratio options

Loading preview...

Rounded Corners

Border radius options

Loading preview...

With Fallback

Fallback content for loading/error states

Loading preview...

Props

PropTypeDefaultDescription
srcRequiredstringNot setImage source URL
altRequiredstringNot setAlt text for accessibility (required)
aspectRatioenum1:14:316:921:9autoautoAspect ratio of the image container
objectFitenumcovercontainfillnonecoverHow the image fits within its container
widthunionNot setWidth of the image container
heightunionNot setHeight of the image container
roundedenumnonesmmdlgfullnoneBorder radius
fallbacknodeNot setContent to show while loading or on error
classNamestringNot setAdditional class name
styleobjectNot setInline styles
imgPropsobjectNot setAdditional props for the underlying img element (except src/alt/size/style/events)
onImageLoadfunctionNot setCalled when the underlying img element loads
onImageErrorfunctionNot setCalled when the underlying img element fails to load

Usage Guidelines

When to use

  • Displaying product images in cards or grids
  • Hero images with specific aspect ratios
  • User-uploaded content that may fail to load
  • Thumbnails in lists or galleries

When not to use

  • User avatars (use Avatar component)
  • Icons or symbols (use Icon component)
  • Background images (use CSS background-image)
  • SVG illustrations (use inline SVG or Image component)

Best practices

  • Always provide meaningful alt text for accessibility
  • Use appropriate aspect ratios for consistent layouts
  • Provide fallback content for failed loads
  • Use objectFit="contain" for logos to preserve aspect ratio
  • Use imgProps / onImageLoad / onImageError when you need lower-level img control
Accessibility
  • Alt text is required and must describe the image content
  • Decorative images should have empty alt=""
  • Avoid text in images; if necessary, describe the text in alt
  • Ensure sufficient contrast between image and surrounding content