AI CSS Animations

Inset Border Draw Image Hover

A thin white frame draws itself inside the photo, horizontal lines first, then vertical, and a title fades in at the center. Two pseudo-elements scaled from zero carry the four lines.

Also known as: border draw on image, frame lines hover, inner border image hover.

Explorethe Alps

HTML

<figure class="hfx-image-frame-draw">
  <div class="hfx-image-frame-draw-photo" role="img" aria-label="Snowy peaks"></div>
  <figcaption>Explore<b>the Alps</b></figcaption>
</figure>

CSS

.hfx-image-frame-draw {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 15em;
  height: 9.5em;
  margin: 0;
  border-radius: 0.75em;
  overflow: hidden;
  color: #fff;
  font-family: system-ui, sans-serif;
}
.hfx-image-frame-draw-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%);
  transition: filter 0.5s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-frame-draw::before,
.hfx-image-frame-draw::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0.8em;
  transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-image-frame-draw::before {
  border-top: 0.125em solid #fff;
  border-bottom: 0.125em solid #fff;
  transform: scaleX(0);
}
.hfx-image-frame-draw::after {
  border-left: 0.125em solid #fff;
  border-right: 0.125em solid #fff;
  transform: scaleY(0);
}
.hfx-image-frame-draw figcaption {
  position: relative;
  padding: 0;
  color: inherit;
  font-family: inherit;
  z-index: 1;
  display: grid;
  text-align: center;
  font-size: 0.75em;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(0.5em);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.hfx-image-frame-draw b {
  font-size: 2em;
  letter-spacing: 0.04em;
  text-transform: none;
}
.hfx-image-frame-draw:hover .hfx-image-frame-draw-photo {
  filter: brightness(0.62) saturate(1.2);
  transform: scale(1.05);
}
.hfx-image-frame-draw:hover::before {
  transform: scaleX(1);
}
.hfx-image-frame-draw:hover::after {
  transform: scaleY(1);
  transition-delay: 0.2s;
}
.hfx-image-frame-draw:hover figcaption {
  opacity: 1;
  transform: none;
  transition: opacity 0.4s ease 0.3s, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.3s;
}

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