Image zoom for Astro
Click or tap any photo on this page. It grows from its place to fill the screen, and a group of photos becomes a gallery you can swipe.
- Keyboard and touch
- No dependencies
- Accessible
Wherever your images are
Inside an article
Photos in the flow of text. Smooth liftoff, soft landing: the zoom starts from the image itself and lands back on it, so the eye never loses it.
A gallery
All the images inside one <ImageZoom> form a gallery. Move with the arrows, the ← →keys or a swipe.
Make it yours
Six ready-made themes, from everyday to just for fun. Each is a handful of --image-zoom-* variables: colors for light and dark mode, caption font, spacing, the shape of the controls and the motion, plus a prop or two for the layout. Pick one, open a photo, copy the CSS: on :root for the whole site, or on one gallery as here.
Darkroom
Expo fade · 500msFor photographers: nothing but the picture, almost edge to edge on white or black, no counter, and controls that fade in slowly.
.darkroom {
--image-zoom-bg: light-dark(#ffffff, #000000);
--image-zoom-close-color: light-dark(#111111, #f2f2f2);
--image-zoom-close-bg: light-dark(rgb(236 236 236 / 0.82), rgb(38 38 38 / 0.82));
--image-zoom-nav-color: light-dark(#111111, #f2f2f2);
--image-zoom-nav-bg: light-dark(rgb(236 236 236 / 0.82), rgb(38 38 38 / 0.82));
--image-zoom-caption-color: light-dark(#111111, #f2f2f2);
--image-zoom-caption-bg: light-dark(rgb(255 255 255 / 0.82), rgb(26 26 26 / 0.82));
--image-zoom-caption-font-size: 12px;
--image-zoom-caption-radius: 999px;
--image-zoom-button-size: 36px;
--image-zoom-button-radius: 999px;
--image-zoom-padding: 2vmin;
--image-zoom-image-radius: 0px;
--image-zoom-controls-offset: 16px;
--image-zoom-animation-duration: 500ms;
--image-zoom-easing-in: cubic-bezier(0.16, 1, 0.3, 1);
--image-zoom-easing-out: cubic-bezier(0.7, 0, 0.84, 0);
--image-zoom-slide-duration: 600ms;
--image-zoom-slide-easing: cubic-bezier(0.16, 1, 0.3, 1);
--image-zoom-controls-duration: 700ms;
--image-zoom-controls-easing: cubic-bezier(0.16, 1, 0.3, 1);
--image-zoom-caption-duration: 400ms;
}
/* <ImageZoom class="darkroom" animation="fade" navigationLayout="sides" showCounter={false}> */Editorial
Quart · 600msFor long reads: cream paper or a dark page, a serif caption set like a printed one above the photo, wide margins and a claret accent.
.editorial {
--image-zoom-bg: light-dark(#f6f1e7, #1b1714);
--image-zoom-close-color: light-dark(#ffffff, #1b1714);
--image-zoom-close-bg: light-dark(rgb(122 31 43 / 0.82), rgb(232 168 160 / 0.82));
--image-zoom-nav-color: light-dark(#ffffff, #1b1714);
--image-zoom-nav-bg: light-dark(rgb(122 31 43 / 0.82), rgb(232 168 160 / 0.82));
--image-zoom-caption-color: light-dark(#1f1a17, #efe6d8);
--image-zoom-caption-bg: light-dark(rgb(246 241 231 / 0.82), rgb(27 23 20 / 0.82));
--image-zoom-caption-font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
--image-zoom-caption-font-size: 17px;
--image-zoom-caption-max-width: 560px;
--image-zoom-caption-radius: 0px;
--image-zoom-button-size: 40px;
--image-zoom-button-radius: 0px;
--image-zoom-controls-offset: 20px;
--image-zoom-padding: 10vmin;
--image-zoom-image-radius: 0px;
--image-zoom-animation-duration: 600ms;
--image-zoom-easing-in: cubic-bezier(0.25, 1, 0.5, 1);
--image-zoom-easing-out: cubic-bezier(0.5, 0, 0.75, 0);
--image-zoom-slide-duration: 600ms;
--image-zoom-slide-easing: cubic-bezier(0.25, 1, 0.5, 1);
--image-zoom-caption-enter-x: 120px;
}
/* <ImageZoom class="editorial" captionPosition="top"> */Museum
Slow quart · 750msFor art and archives: a warm grey or deep green wall, a lot of room around the picture, a small label plate and brass controls, in no hurry.
.museum {
--image-zoom-bg: light-dark(#e6e1d6, #1c2621);
--image-zoom-close-color: light-dark(#ffffff, #1c2621);
--image-zoom-close-bg: light-dark(rgb(94 72 24 / 0.82), rgb(212 178 106 / 0.82));
--image-zoom-nav-color: light-dark(#ffffff, #1c2621);
--image-zoom-nav-bg: light-dark(rgb(94 72 24 / 0.82), rgb(212 178 106 / 0.82));
--image-zoom-caption-color: light-dark(#2b2a26, #1c2621);
--image-zoom-caption-bg: light-dark(rgb(251 248 241 / 0.82), rgb(244 239 226 / 0.82));
--image-zoom-caption-font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
--image-zoom-caption-font-size: 13px;
--image-zoom-caption-max-width: 320px;
--image-zoom-caption-radius: 2px;
--image-zoom-button-size: 40px;
--image-zoom-button-radius: 2px;
--image-zoom-controls-offset: 24px;
--image-zoom-padding: 12vmin;
--image-zoom-image-radius: 0px;
--image-zoom-animation-duration: 750ms;
--image-zoom-easing-in: cubic-bezier(0.25, 1, 0.5, 1);
--image-zoom-easing-out: cubic-bezier(0.5, 0, 0.75, 0);
--image-zoom-slide-duration: 800ms;
--image-zoom-slide-easing: cubic-bezier(0.25, 1, 0.5, 1);
--image-zoom-caption-duration: 500ms;
--image-zoom-caption-enter-y: 6px;
}
/* <ImageZoom class="museum" navigationLayout="sides" showCounter={false}> */Blueprint
Mechanical · 220msFor maps, diagrams and technical docs: blueprint blue, monospaced labels, a counter to keep your place and a quick, mechanical zoom.
.blueprint {
--image-zoom-bg: light-dark(#e8f0fb, #0a2a5e);
--image-zoom-close-color: light-dark(#ffffff, #0a2a5e);
--image-zoom-close-bg: light-dark(rgb(11 61 145 / 0.82), rgb(219 232 255 / 0.82));
--image-zoom-nav-color: light-dark(#ffffff, #0a2a5e);
--image-zoom-nav-bg: light-dark(rgb(11 61 145 / 0.82), rgb(219 232 255 / 0.82));
--image-zoom-caption-color: light-dark(#0b3d91, #ffffff);
--image-zoom-caption-bg: light-dark(rgb(255 255 255 / 0.82), rgb(13 58 122 / 0.82));
--image-zoom-caption-font: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
--image-zoom-caption-font-size: 12px;
--image-zoom-caption-radius: 2px;
--image-zoom-button-size: 36px;
--image-zoom-button-radius: 2px;
--image-zoom-controls-offset: 16px;
--image-zoom-padding: 5vmin;
--image-zoom-image-radius: 0px;
--image-zoom-animation-duration: 220ms;
--image-zoom-easing-in: cubic-bezier(0.2, 0, 0, 1);
--image-zoom-easing-out: cubic-bezier(0.3, 0, 1, 1);
--image-zoom-slide-duration: 200ms;
--image-zoom-slide-easing: linear;
--image-zoom-caption-duration: 0ms;
}
/* <ImageZoom class="blueprint"> */Arcade
8-bit steps · 450msHot pink, cyan and yellow on deep purple, square pixels and a zoom in five frames, like an 8-bit game.
.arcade {
--image-zoom-bg: light-dark(#fff0fa, #16062c);
--image-zoom-close-color: light-dark(#ffffff, #1a0628);
--image-zoom-close-bg: light-dark(rgb(168 14 95 / 0.82), rgb(255 92 184 / 0.82));
--image-zoom-nav-color: light-dark(#ffffff, #1a0628);
--image-zoom-nav-bg: light-dark(rgb(7 85 96 / 0.82), rgb(62 230 245 / 0.82));
--image-zoom-caption-color: light-dark(#ffe74c, #1a0628);
--image-zoom-caption-bg: light-dark(rgb(59 10 92 / 0.82), rgb(255 231 76 / 0.82));
--image-zoom-caption-font: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
--image-zoom-caption-font-size: 12px;
--image-zoom-caption-radius: 0px;
--image-zoom-button-size: 48px;
--image-zoom-button-radius: 0px;
--image-zoom-padding: 5vmin;
--image-zoom-image-radius: 0px;
--image-zoom-animation-duration: 450ms;
--image-zoom-easing-in: steps(5, jump-none);
--image-zoom-easing-out: steps(5, jump-none);
--image-zoom-slide-duration: 360ms;
--image-zoom-slide-easing: steps(4, jump-none);
--image-zoom-controls-duration: 200ms;
--image-zoom-controls-easing: steps(2, jump-none);
--image-zoom-caption-duration: 0ms;
}
/* <ImageZoom class="arcade" captionPosition="top" navigationLayout="sides"> */Bubblegum
Spring · 400msPlayful and soft: candy pink or plum, big round buttons, round photos and a springy zoom that overshoots and settles.
.bubblegum {
--image-zoom-bg: light-dark(#ffe4f1, #2a0f2e);
--image-zoom-close-color: light-dark(#ffffff, #2a0f2e);
--image-zoom-close-bg: light-dark(rgb(173 20 87 / 0.82), rgb(255 179 220 / 0.82));
--image-zoom-nav-color: light-dark(#ffffff, #2a0f2e);
--image-zoom-nav-bg: light-dark(rgb(173 20 87 / 0.82), rgb(255 179 220 / 0.82));
--image-zoom-caption-color: light-dark(#4a0d33, #2a0f2e);
--image-zoom-caption-bg: light-dark(rgb(255 255 255 / 0.82), rgb(255 240 247 / 0.82));
--image-zoom-caption-font-size: 15px;
--image-zoom-caption-radius: 999px;
--image-zoom-button-size: 56px;
--image-zoom-button-radius: 999px;
--image-zoom-controls-offset: 28px;
--image-zoom-padding: 7vmin;
--image-zoom-image-radius: 28px;
--image-zoom-animation-duration: 400ms;
--image-zoom-easing-in: linear(0, 0.041 3%, 0.143 6%, 0.283 9%, 0.438 12%, 0.642 16%, 0.819 20%, 0.984 25%, 1.082 30%, 1.122 35%, 1.122 40%, 1.093 46%, 1.054 52%, 1.020 58%, 0.995 65%, 0.985 72%, 0.986 80%, 0.994 90%, 1);
--image-zoom-slide-duration: 400ms;
--image-zoom-slide-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
--image-zoom-caption-duration: 400ms;
--image-zoom-caption-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
--image-zoom-caption-enter-y: 20px;
}
/* <ImageZoom class="bubblegum" navigationLayout="sides"> */Built in
Keyboard
Tab to a photo and press Enter; the arrow keys move, and Escape closes with the focus on the photo you ended on.
Screen readers
A native dialog with labelled controls; each image keeps its alt text, and the caption is announced as you move.
Touch and touchpad
Swipe between photos with the inertia of a real carousel; a vertical swipe or a scroll closes the zoom.
Works without JavaScript
Each photo is wrapped in a link to the file the zoom opens, so it opens even before the script loads.
Safe from your CSS
A shadow root keeps your styles out of the zoom and the zoom out of your page; you change it on purpose, with CSS variables and parts.
Motion you can tune
Zoom or fade, any CSS easing from springs to steps, and captions that glide in with each photo; with reduced motion, it all stays still.
Get started
1. Install
2. Wrap your images
Every image inside opens in the zoom. When the page shows a smaller file, such as a thumbnail or Astro's
<Image>, give the zoom the full-size one: see how. On a Starlight site, the plugin does it with one line in the config.--- import ImageZoom from 'astro-image-zoom/ImageZoom.astro'; --- <ImageZoom> <img src="/earthrise.jpg" alt="Earth rising above the Moon" /> </ImageZoom>3. Customize it
Options for the navigation, the caption and how it closes; colors, spacing, shapes and motion with CSS variables.
Read the docs



































