AI CSS Animations

Copy Icon Hover

The two sheets of a copy icon spread apart on hover and a third copy slides out between them, so the icon literally shows duplicates. Each sheet is filled to hide the one behind it.

Also known as: copy to clipboard icon animation, duplicate icon hover css, layers icon hover.

HTML

<button class="hfx-copy-icon-layers" aria-label="Copy to clipboard"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect class="hfx-copy-icon-layers-back" x="3" y="3" width="12" height="12" rx="2.5"/><rect class="hfx-copy-icon-layers-mid" x="6" y="6" width="12" height="12" rx="2.5"/><rect class="hfx-copy-icon-layers-front" x="9" y="9" width="12" height="12" rx="2.5"/></svg></button>

CSS

.hfx-copy-icon-layers {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 3.5em;
  height: 3.5em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  border-radius: 0.85em;
  background: var(--c);
  color: #fff;
  transition: box-shadow 0.3s ease;}
.hfx-copy-icon-layers svg {
  width: 1.6em;
  height: 1.6em;
  overflow: visible;
}
.hfx-copy-icon-layers rect {
  fill: var(--c);
  transform-box: view-box;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}
.hfx-copy-icon-layers-mid {
  opacity: 0;
  transform: translate(12.5%, 12.5%);
}
.hfx-copy-icon-layers:is(:hover, :focus-visible) { box-shadow: 0 0.45em 1em color-mix(in srgb, var(--c) 35%, transparent); }
.hfx-copy-icon-layers:is(:hover, :focus-visible) .hfx-copy-icon-layers-back { transform: translate(-7%, -7%); }
.hfx-copy-icon-layers:is(:hover, :focus-visible) .hfx-copy-icon-layers-mid {
  opacity: 1;
  transform: translate(0, 0);
}
.hfx-copy-icon-layers:is(:hover, :focus-visible) .hfx-copy-icon-layers-front { transform: translate(7%, 7%); }

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