AI CSS Animations

Offset Border Image Hover

An accent outline sits offset from the photo like a misregistered print, and on hover the two slide together until the frame lines up with the edges. Portfolio headshots use this a lot.

Also known as: offset outline image, portfolio photo border hover, shifted frame hover.

HTML

<a href="#" class="hfx-image-offset-frame" aria-label="View project">
  <span class="hfx-image-offset-frame-photo"></span>
</a>

CSS

.hfx-image-offset-frame {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  display: block;
  width: 13em;
  height: 8.25em;
}
.hfx-image-offset-frame-photo,
.hfx-image-offset-frame::after {
  position: absolute;
  inset: 0;
  border-radius: 0.6em;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-offset-frame-photo {
  background:
    radial-gradient(9% 30% at 50% 74%, rgb(255 255 255 / 0.55), transparent),
    linear-gradient(transparent 62%, color-mix(in srgb, var(--c) 78%, #0f172a) 62%, color-mix(in srgb, var(--c) 62%, #0f172a) 74%, color-mix(in srgb, var(--c) 40%, #020617)),
    radial-gradient(34% 16% at 6% 63%, color-mix(in srgb, var(--c) 36%, #0f172a) 99%, transparent),
    radial-gradient(20% 9% at 92% 62%, color-mix(in srgb, var(--c) 48%, #1e293b) 99%, transparent),
    radial-gradient(circle at 50% 50%, #fffbeb 0 0.9em, rgb(254 243 199 / 0.5) 1em, transparent 3.6em),
    linear-gradient(color-mix(in srgb, var(--c) 56%, #fff), color-mix(in srgb, var(--c) 18%, #fed7aa) 62%);
  transform: translate(-0.35em, -0.35em);
}
.hfx-image-offset-frame::after {
  content: "";
  border: 0.14em solid var(--c);
  transform: translate(0.35em, 0.35em);
}
.hfx-image-offset-frame:is(:hover, :focus-visible) .hfx-image-offset-frame-photo,
.hfx-image-offset-frame:is(:hover, :focus-visible)::after {
  transform: none;
}

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

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<a href="#" class="group relative block h-32 w-52">
  <span class="absolute inset-0 -translate-x-1.5 -translate-y-1.5 rounded-lg bg-gradient-to-b from-orange-200 via-sky-300 to-blue-700 transition-transform duration-300 group-hover:translate-x-0 group-hover:translate-y-0"></span>
  <span class="absolute inset-0 translate-x-1.5 translate-y-1.5 rounded-lg border-2 border-blue-500 transition-transform duration-300 group-hover:translate-x-0 group-hover:translate-y-0"></span>
</a>

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