Split and assemble an image using CSS mask

Published: (December 31, 2025 at 04:26 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Demo

Check out this Pen I made!

Split an image into pieces using the mask property, then show it fully on hover. A single‑element implementation using fewer than 10 CSS declarations.

img {
  width: 280px;
  aspect-ratio: 1;
  box-sizing: border-box;
  --_g: var(--g)/calc(50% - var(--g)) calc(50% - var(--g)) 
    no-repeat conic-gradient(#000 0 0);
  mask: 
    left   var(--_i,) top    var(--_g),
    bottom var(--_i,) left   var(--_g),
    top    var(--_i,) right  var(--_g),
    right  var(--_i,) bottom var(--_g);
  transition: .3s linear;
}
img:hover {
  --_i: var(--g);
  padding: var(--g);
}
Back to Blog

Related posts

Read more »

CSS @property: advanced theming

When theming a web application, CSS variables are the simplest and most convenient way to manage values. While they are often used for global settings, the @pro...