AI CSS Animations

Grayscale to Color Image

Images sit in black and white until hovered, then bloom into color and grow a touch. A filter transition does all the work, so it applies to any img or background.

Also known as: black and white hover, color on hover, desaturate hover.

HTML

<div class="hfx-image-grayscale" role="img" aria-label="Sample image"></div>

CSS

.hfx-image-grayscale {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  width: 12em;
  aspect-ratio: 4 / 3;
  border-radius: 0.75em;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 45%, #fff), var(--c));
  filter: grayscale(1);
  transition: filter 0.4s ease, transform 0.4s ease;
}
.hfx-image-grayscale:hover {
  filter: grayscale(0);
  transform: scale(1.03);
}

@media (prefers-reduced-motion: reduce) {
  .hfx-image-grayscale, .hfx-image-grayscale *, .hfx-image-grayscale::before, .hfx-image-grayscale::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects