AI CSS Animations

Duotone to Color Image Hover

The photo sits as a two-color print, dark plum shadows and accent highlights, then washes into full color on hover. A multiply layer and a lighten layer over a grayscale photo make the duotone.

Also known as: duotone image css, two tone image hover, spotify duotone effect.

HTML

<div class="hfx-image-duotone" role="img" aria-label="Mountain range">
  <div class="hfx-image-duotone-photo"></div>
</div>

CSS

.hfx-image-duotone {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  isolation: isolate;
  width: 15em;
  height: 9.5em;
  border-radius: 0.75em;
  overflow: hidden;
}
.hfx-image-duotone-photo {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(74% 44% at 20% 110%, color-mix(in srgb, var(--c) 42%, #0f172a) 99%, transparent),
    radial-gradient(62% 36% at 90% 107%, color-mix(in srgb, var(--c) 56%, #0f172a) 99%, transparent),
    conic-gradient(from 130deg at 72% 40%, transparent 0, color-mix(in srgb, var(--c) 80%, #1e293b) 0.4deg 99.6deg, transparent 100deg),
    conic-gradient(from 118deg at 94% 55%, transparent 0, color-mix(in srgb, var(--c) 80%, #1e293b) 0.4deg 123.6deg, transparent 124deg),
    conic-gradient(from 124deg at 30% 36%, transparent 0, color-mix(in srgb, var(--c) 48%, #fff) 0.4deg 111.6deg, transparent 112deg),
    conic-gradient(from 126deg at 52% 50%, transparent 0, color-mix(in srgb, var(--c) 48%, #fff) 0.4deg 107.6deg, transparent 108deg),
    radial-gradient(circle at 55% 27%, #fff 0 0.85em, rgb(255 255 255 / 0.45) 0.95em, transparent 3.2em),
    linear-gradient(color-mix(in srgb, var(--c) 64%, #fff), color-mix(in srgb, var(--c) 12%, #fff7ed) 72%);
  filter: grayscale(1) contrast(1.25);
  transition: filter 0.5s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-duotone::before,
.hfx-image-duotone::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  transition: opacity 0.5s ease;
}
.hfx-image-duotone::before {
  background: color-mix(in srgb, var(--c) 75%, #fff);
  mix-blend-mode: multiply;
}
.hfx-image-duotone::after {
  background: color-mix(in srgb, var(--c) 20%, #4a0d3a);
  mix-blend-mode: lighten;
}
.hfx-image-duotone:hover .hfx-image-duotone-photo {
  filter: none;
  transform: scale(1.04);
}
.hfx-image-duotone:hover::before,
.hfx-image-duotone:hover::after {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .hfx-image-duotone, .hfx-image-duotone *, .hfx-image-duotone::before, .hfx-image-duotone::after, .hfx-image-duotone *::before, .hfx-image-duotone *::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