Default

Basic image in a figure with rounded corners and cover fit.

Abstract gradient
<figure class="image">
  <img src="photo.jpg" alt="Description" />
</figure>

With Caption

Semantic <figcaption> for descriptive text below the image.

Abstract gradient
Photo by Unsplash — Abstract gradient composition
<figure class="image">
  <img src="photo.jpg" alt="Description" />
  <figcaption class="image-caption">Caption text</figcaption>
</figure>

Fallback

Shows a placeholder when the image fails to load. Uses :has() to detect error state.

Broken image example
<figure class="image">
  <img src="photo.jpg" alt="Description" />
  <div class="image-fallback">
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
      <rect width="18" height="18" x="3" y="3" rx="2" ry="2"/>
      <circle cx="9" cy="9" r="2"/>
      <path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/>
    </svg>
  </div>
</figure>

Lightbox Preview

Click the image to open a fullscreen preview with zoom and rotate controls. Uses native <dialog>.

Mountain landscape
Click to preview — Mountain landscape
<figure class="image" data-preview>
  <img src="photo.jpg" alt="Description" />
</figure>

Aspect Ratios

Controlled aspect ratios via data-ratio.

Square
1:1
Standard
4:3
Widescreen
16:9
Portrait
3:4
<figure class="image" data-ratio="1/1">...</figure>
<figure class="image" data-ratio="4/3">...</figure>
<figure class="image" data-ratio="16/9">...</figure>
<figure class="image" data-ratio="3/4">...</figure>

Object Fit

Control how the image fills its container via data-fit.

Cover (default)
cover (default)
Contain
contain
None
none
<!-- default: cover -->
<figure class="image" data-ratio="4/3">...</figure>

<!-- contain -->
<figure class="image" data-ratio="4/3" data-fit="contain">...</figure>

<!-- none (natural size, clipped) -->
<figure class="image" data-ratio="4/3" data-fit="none">...</figure>

Border Radius

Control border radius via data-radius.

No radius
none
Small radius
sm
Default radius
default (lg)
Full radius
full
<figure class="image" data-radius="none">...</figure>
<figure class="image" data-radius="sm">...</figure>
<figure class="image">...</figure>  <!-- default: lg -->
<figure class="image" data-radius="full">...</figure>

CSS view file

Styles for figure, caption, fallback, and lightbox dialog.

JavaScript view file

Fallback error detection and lightbox preview with zoom/rotate.