ImageGallery
A responsive image grid with a native <dialog> lightbox — click any thumbnail to open a fullscreen viewer with prev/next navigation, captions, and keyboard support.
Preview
Usage
import { ImageGallery } from "anexui";
<ImageGallery
images={[
{ src: "/img/a.jpg", alt: "Description", caption: "Optional caption" },
{ src: "/img/b.jpg", alt: "Description" },
]}
cols={3}
gap="md"
lightbox
/>
Copy codeColumn layouts
<ImageGallery images={images} cols={2} gap="lg" />
<ImageGallery images={images} cols={3} gap="md" />
<ImageGallery images={images} cols={4} gap="sm" />
Copy codeAspect ratios
<ImageGallery images={images} aspectRatio="square" /> {/* 1:1 — default */}
<ImageGallery images={images} aspectRatio="video" /> {/* 16:9 */}
<ImageGallery images={images} aspectRatio="portrait" /> {/* 3:4 */}
<ImageGallery images={images} aspectRatio="auto" /> {/* natural image ratio */}
Copy codeWithout lightbox
<ImageGallery images={images} lightbox={false} />
Lightbox keyboard controls
| Key | Action |
|---|---|
| ← / → | Previous / next image |
| Escape | Close lightbox |
| Click backdrop | Close lightbox |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| images | GalleryImage[] | — | Array of image objects |
| cols | 2 \| 3 \| 4 | 3 | Number of grid columns |
| gap | "sm" \| "md" \| "lg" | "md" | Gap between thumbnails |
| lightbox | boolean | true | Enable click-to-fullscreen viewer |
| aspectRatio | "square" \| "video" \| "portrait" \| "auto" | "square" | Thumbnail aspect ratio |
| className | string | — | Extra class names on the grid wrapper |
GalleryImage type
| Field | Type | Description |
|---|---|---|
| src | string | Image URL |
| alt | string | Alt text (required for accessibility) |
| caption | string | Optional caption shown on thumbnail hover and in lightbox |
Accessibility
- All images require meaningful
alttext - Lightbox uses a native
<dialog>witharia-labelset to the active image's alt text - Navigation buttons have descriptive
aria-labelattributes - Thumbnails use
loading="lazy"for performance