AI CSS Animations

Slide Up Caption Image Hover

The title rests on a soft scrim at the bottom of the photo, and on hover the whole caption rises to make room for a second line while the accent bar stretches. Good for blog and news covers.

Also known as: caption slide up on hover, image title hover reveal, blog cover hover.

HTML

<a href="#" class="hfx-image-caption-push">
  <span class="hfx-image-caption-push-photo" aria-hidden="true"></span>
  <span class="hfx-image-caption-push-caption">
    <strong>A night above the clouds</strong>
    <small>Travel notes, 4 min read</small>
  </span>
</a>

CSS

.hfx-image-caption-push {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  display: block;
  width: 15em;
  height: 9.5em;
  border-radius: 0.75em;
  overflow: hidden;
  color: #fff;
  font-family: system-ui, sans-serif;
  text-decoration: none;
}
.hfx-image-caption-push-photo {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(72% 42% at 22% 110%, color-mix(in srgb, var(--c) 10%, #020617) 99%, transparent),
    radial-gradient(64% 36% at 86% 107%, color-mix(in srgb, var(--c) 14%, #020617) 99%, transparent),
    conic-gradient(from 129deg at 70% 42%, transparent 0, color-mix(in srgb, var(--c) 22%, #0b1026) 0.4deg 101.6deg, transparent 102deg),
    conic-gradient(from 118deg at 92% 54%, transparent 0, color-mix(in srgb, var(--c) 22%, #0b1026) 0.4deg 123.6deg, transparent 124deg),
    conic-gradient(from 124deg at 28% 38%, transparent 0, color-mix(in srgb, var(--c) 36%, #111a3a) 0.4deg 111.6deg, transparent 112deg),
    conic-gradient(from 126deg at 50% 52%, transparent 0, color-mix(in srgb, var(--c) 36%, #111a3a) 0.4deg 107.6deg, transparent 108deg),
    radial-gradient(circle at 12% 18%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 24% 30%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 38% 12%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 46% 26%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 62% 16%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 88% 22%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 84% 40%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 8% 42%, #fff 0 0.05em, transparent 0.09em),
    radial-gradient(circle at 76% 24%, #f8fafc 0 0.65em, rgb(248 250 252 / 0.3) 0.75em, transparent 2.6em),
    linear-gradient(color-mix(in srgb, var(--c) 20%, #020617), color-mix(in srgb, var(--c) 52%, #1e1b4b) 82%);
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-caption-push::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(transparent 30%, rgb(2 6 23 / 0.85));
  opacity: 0.75;
  transition: opacity 0.4s ease;
}
.hfx-image-caption-push-caption {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 0.35em;
  padding: 0 1em 0.9em;
  transform: translateY(1.35em);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-caption-push-caption::before {
  content: "";
  width: 1.6em;
  height: 0.18em;
  border-radius: 1em;
  background: var(--c);
  transform-origin: 0 50%;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-caption-push strong {
  font-size: 1.05em;
  line-height: 1.2;
}
.hfx-image-caption-push small {
  font-size: 0.75em;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.hfx-image-caption-push:is(:hover, :focus-visible) .hfx-image-caption-push-photo {
  transform: scale(1.06);
}
.hfx-image-caption-push:is(:hover, :focus-visible)::after {
  opacity: 1;
}
.hfx-image-caption-push:is(:hover, :focus-visible) .hfx-image-caption-push-caption {
  transform: none;
}
.hfx-image-caption-push:is(:hover, :focus-visible) .hfx-image-caption-push-caption::before {
  transform: scaleX(2);
}
.hfx-image-caption-push:is(:hover, :focus-visible) small {
  opacity: 0.8;
  transition-delay: 0.12s;
}

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