22 CSS Image Galleries13 / 22

Pure CSSMIT licensed

CSS Mosaic Zoom Gallery

A crisp mosaic grid where hovering a tile zooms its photo cleanly inside the frame — the image scales, the tile doesn't, so nothing overlaps its neighbours. The catalog zoom-on-hover micro-interaction, done the performant way.

Published Updated

Live Demo
Try it

The code

<section class="gl-10" aria-label="Mosaic zoom gallery">
  <div class="gl-10__grid">
    <figure class="gl-10__tile gl-10__tile--big"><img src="https://loremflickr.com/800/800/landscape?lock=1001" alt="Golden hour over rolling hills" loading="lazy" decoding="async"><figcaption>Hills</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/flower,macro?lock=1002" alt="Macro of a flower" loading="lazy" decoding="async"><figcaption>Bloom</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/wildlife?lock=1003" alt="Wild deer in a field" loading="lazy" decoding="async"><figcaption>Wildlife</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/leaf?lock=1004" alt="Backlit green leaf" loading="lazy" decoding="async"><figcaption>Detail</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/waterfall,forest?lock=1005" alt="Forest waterfall" loading="lazy" decoding="async"><figcaption>Falls</figcaption></figure>
    <figure class="gl-10__tile gl-10__tile--wide"><img src="https://loremflickr.com/800/400/panorama,valley?lock=1006" alt="Valley panorama" loading="lazy" decoding="async"><figcaption>Valley</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/sky,clouds?lock=1007" alt="Dramatic cloudscape" loading="lazy" decoding="async"><figcaption>Sky</figcaption></figure>
  </div>
</section>
.gl-10,
.gl-10 *,
.gl-10 *::before,
.gl-10 *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.gl-10 ::selection {
  background: oklch(0.6 0.15 145);
  color: #fff;
}

.gl-10 {
  --accent: oklch(0.58 0.15 145);
  font-family: 'Segoe UI',system-ui,sans-serif;
  width: 100%;
  min-height: 100vh;
  padding: 40px 20px;
  background: #f2f4f1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gl-10__grid {
  width: min(820px,100%);
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4,1fr);
  grid-auto-rows: 1fr;
  grid-auto-flow: dense;
}

.gl-10__tile {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: #dfe4de;
  aspect-ratio: 1/1;
}

.gl-10__tile--big {
  grid-column: span 2;
  grid-row: span 2;
  aspect-ratio: auto;
}

.gl-10__tile--wide {
  grid-column: span 2;
  aspect-ratio: auto;
}

.gl-10__tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1);
  transition: transform .55s cubic-bezier(.2,.7,.2,1);
}

.gl-10__tile:hover img,
.gl-10__tile:focus-within img {
  transform: scale(1.16);
}

.gl-10__tile figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px 12px 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  background: linear-gradient(0deg,rgba(8,20,12,.75),transparent);
  opacity: 0;
  transition: opacity .35s;
}

.gl-10__tile:hover figcaption,
.gl-10__tile:focus-within figcaption {
  opacity: 1;
}

@media (max-width: 600px) {
  .gl-10__grid {
    grid-template-columns: repeat(2,1fr);
  }

  .gl-10__tile--big,
    .gl-10__tile--wide {
    grid-column: span 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gl-10__tile img,
    .gl-10__tile figcaption {
    transition: none;
  }
}
/* No JavaScript — the image scales inside an overflow:hidden tile, so the zoom is contained. */
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Image Gallerie from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: CSS Mosaic Zoom Gallery
Source: https://codefronts.com/snippets/css-image-gallery/css-mosaic-zoom-gallery/

A crisp mosaic grid where hovering a tile zooms its photo cleanly inside the frame — the image scales, the tile doesn't, so nothing overlaps its neighbours. The catalog zoom-on-hover micro-interaction, done the performant way.
## HTML
```html
<section class="gl-10" aria-label="Mosaic zoom gallery">
  <div class="gl-10__grid">
    <figure class="gl-10__tile gl-10__tile--big"><img src="https://loremflickr.com/800/800/landscape?lock=1001" alt="Golden hour over rolling hills" loading="lazy" decoding="async"><figcaption>Hills</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/flower,macro?lock=1002" alt="Macro of a flower" loading="lazy" decoding="async"><figcaption>Bloom</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/wildlife?lock=1003" alt="Wild deer in a field" loading="lazy" decoding="async"><figcaption>Wildlife</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/leaf?lock=1004" alt="Backlit green leaf" loading="lazy" decoding="async"><figcaption>Detail</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/waterfall,forest?lock=1005" alt="Forest waterfall" loading="lazy" decoding="async"><figcaption>Falls</figcaption></figure>
    <figure class="gl-10__tile gl-10__tile--wide"><img src="https://loremflickr.com/800/400/panorama,valley?lock=1006" alt="Valley panorama" loading="lazy" decoding="async"><figcaption>Valley</figcaption></figure>
    <figure class="gl-10__tile"><img src="https://loremflickr.com/400/400/sky,clouds?lock=1007" alt="Dramatic cloudscape" loading="lazy" decoding="async"><figcaption>Sky</figcaption></figure>
  </div>
</section>
```
## CSS
```css
.gl-10,
.gl-10 *,
.gl-10 *::before,
.gl-10 *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.gl-10 ::selection {
  background: oklch(0.6 0.15 145);
  color: #fff;
}

.gl-10 {
  --accent: oklch(0.58 0.15 145);
  font-family: 'Segoe UI',system-ui,sans-serif;
  width: 100%;
  min-height: 100vh;
  padding: 40px 20px;
  background: #f2f4f1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gl-10__grid {
  width: min(820px,100%);
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4,1fr);
  grid-auto-rows: 1fr;
  grid-auto-flow: dense;
}

.gl-10__tile {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: #dfe4de;
  aspect-ratio: 1/1;
}

.gl-10__tile--big {
  grid-column: span 2;
  grid-row: span 2;
  aspect-ratio: auto;
}

.gl-10__tile--wide {
  grid-column: span 2;
  aspect-ratio: auto;
}

.gl-10__tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1);
  transition: transform .55s cubic-bezier(.2,.7,.2,1);
}

.gl-10__tile:hover img,
.gl-10__tile:focus-within img {
  transform: scale(1.16);
}

.gl-10__tile figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px 12px 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  background: linear-gradient(0deg,rgba(8,20,12,.75),transparent);
  opacity: 0;
  transition: opacity .35s;
}

.gl-10__tile:hover figcaption,
.gl-10__tile:focus-within figcaption {
  opacity: 1;
}

@media (max-width: 600px) {
  .gl-10__grid {
    grid-template-columns: repeat(2,1fr);
  }

  .gl-10__tile--big,
    .gl-10__tile--wide {
    grid-column: span 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gl-10__tile img,
    .gl-10__tile figcaption {
    transition: none;
  }
}
```

## JavaScript
```js
/* No JavaScript — the image scales inside an overflow:hidden tile, so the zoom is contained. */
```

How this works

A CSS Grid mosaic mixes a couple of feature tiles (spanning two tracks) with standard cells. Each tile has overflow: hidden; the <img> inside scales with transform: scale() on hover/focus. Because only the image transforms and the tile clips it, the zoom is fully contained — no reflow, no overlap, and the whole thing stays on the compositor.

A soft caption scrim fades in on hover to label each shot without cluttering the resting grid.

Make it yours

  • Set the zoom depth with the hover scale() (1.1 subtle, 1.25 punchy).
  • Promote any tile to a feature by giving it a grid span.
  • Nudge transform-origin toward a subject to zoom into the focal point.
  • Replace the scrim caption with a category chip or icon.

Gotchas — read before shipping

  • Scale the image, never the tile — scaling the tile pushes neighbours and reflows the grid.
  • overflow: hidden on the tile is what contains the zoom; without it the image spills over adjacent cells.
  • Fixed aspect-ratio on tiles keeps the mosaic aligned regardless of source image size.

Browser support

ChromeSafariFirefoxEdge
111+15.4+113+111+

Floor set by oklch() as this demo is written. The core technique itself goes back further — Chrome 57+.

CSS Grid + transform scale + overflow clip — universally supported.

Techniques used in this demo

Search CodeFronts

Loading…