Image

PreviousNext

A flexible, practical image component with three clear sizing modes for web and mobile applications

Image component built on Next.js Image with three sizing modes: explicit (width + height), constrained (one dimension + aspectRatio), and responsive (aspectRatio + Tailwind classes).

Basic Usage

Responsive with Aspect Ratio

Use aspectRatio with Tailwind responsive classes for container-responsive images.

Responsive image

Width-Constrained

Specify width + aspectRatio for images with fixed width and proportional height.

Product photo

Height-Constrained

Specify height + aspectRatio for images with fixed height and proportional width.

Story format

Aspect Ratios

All standard aspect ratios for modern web and mobile applications.

16:9 (Widescreen)

Widescreen ratio

9:16 (Portrait)

Portrait ratio

1:1 (Square)

Square ratio

4:3 (Standard)

Standard ratio

Preset Sizes

Convenience presets for common widths (xs: 64px, sm: 96px, md: 192px, lg: 384px, xl: 512px).

xs (64px)

Extra small

sm (96px)

Small

md (192px)

Medium

Fit Options

Control how images fill their containers: cover (fills container, may crop) vs contain (fits entirely, may have space).

Cover (default)

Fills container, may crop

Cover fit

Contain

Full image visible

Contain fit

Rounded Variants

Choose from multiple corner radius options.

None
Small
Medium
Large
Full

Avatars & Profiles

For circular profile images, use the Avatar component directly for optimal rendering.

JDJDJDJD

Interactive Features

Enable openOnClick to display images in a full-screen lightbox.

Error Handling

The component automatically handles image loading errors with fallback content.

// Default fallback (shows first 2 characters of alt text)
<Image
  src={failedUrl}
  alt="Fallback Demo"
  width={80}
  aspectRatio="1:1"
  rounded="full"
/>
 
// Custom fallback content
<Image
  src={failedUrl}
  alt="Custom Fallback"
  width={80}
  aspectRatio="1:1"
  rounded="full"
  fallback={<span className="text-xs">🖼️</span>}
/>
 
// With error callback
<Image
  src={imageUrl}
  alt="Image"
  width={200}
  aspectRatio="1:1"
  onError={() => console.log('Image failed to load')}
/>

Common Patterns

Real-world usage examples for typical UI scenarios.

Profile Card

JD

John Doe

Product Designer

Product Grid

Product Name

$99.00

Product Name

$149.00

Product Name

$79.00

Hero Banner

Hero banner

Explore Nature

Discover breathtaking landscapes

Story/Portrait Format

Story

Props

PropTypeDefaultDescription
srcstring-Required. Image source URL
altstring-Required. Alternative text for accessibility
widthnumber | string-Fixed width in pixels or CSS value
heightnumber | string-Fixed height in pixels or CSS value
aspectRatio"1:1" | "4:3" | "3:2" | "16:9" | "21:9" | "9:16" | "2:3" | number-Aspect ratio constraint
preset"xs" | "sm" | "md" | "lg" | "xl"-Preset width (64/96/192/384/512px)
fit"cover" | "contain""cover"How image fills container
objectPositionstring-CSS object-position value
rounded"none" | "sm" | "md" | "lg" | "full""md"Corner radius variant
loading"lazy" | "eager""lazy"Image loading strategy
prioritybooleanfalseNext.js Image priority loading
openOnClickbooleanfalseEnable lightbox on click
onClick() => void-Custom click handler
fallbackReactNode-Custom fallback content for errors
onError() => void-Error callback
classNamestring-Image element classes
containerClassNamestring-Container element classes