AI CSS Animations

Link Preview Tooltip With Image

A link that drops a preview card with a thumbnail, title, summary and URL. The picture settles from a slow zoom as it opens. The thumbnail here is drawn in CSS, so swap in your img.

Also known as: image preview on hover css, link hover card, wikipedia style link preview.

Alpine lakes guide Alpine Lakes Guide Routes, maps and the best time to go. trails.example/lakes

HTML

<span class="tip-link-preview">
  <a href="#" aria-describedby="tip-link-preview-tip">Alpine lakes guide<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 16 16 8M9.5 8H16v6.5"/></svg></a>
  <span class="tip-link-preview-tip" id="tip-link-preview-tip" role="tooltip">
    <span class="tip-link-preview-img" aria-hidden="true"><span class="tip-link-preview-scene"></span></span>
    <span class="tip-link-preview-text">
      <b>Alpine Lakes Guide</b>
      Routes, maps and the best time to go.
      <small>trails.example/lakes</small>
    </span>
  </span>
</span>

CSS

.tip-link-preview {
  --c: var(--tip-color, #3b82f6);
  font-size: var(--tip-size, 16px);
  position: relative;
  display: inline-flex;
  margin-bottom: 5em; /* room for the card in this preview */
}
.tip-link-preview a {
  display: inline-flex;
  align-items: center;
  gap: 0.15em;
  border-radius: 0.2em;
  color: var(--c);
  font: 600 1em/1.4 system-ui, sans-serif;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--c) 40%, transparent);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.25em;
  transition: text-decoration-color 0.2s ease;
}
.tip-link-preview svg {
  width: 1em;
  height: 1em;
  transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.tip-link-preview:hover a { text-decoration-color: var(--c); }
.tip-link-preview:hover svg { transform: translate(0.12em, -0.12em); }
.tip-link-preview a:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}
.tip-link-preview-tip {
  position: absolute;
  top: calc(100% + 0.7em);
  left: 50%;
  z-index: 10;
  display: flex;
  gap: 0.8em;
  box-sizing: border-box;
  width: 21em;
  padding: 0.6em 0.8em 0.6em 0.6em;
  border: 1px solid rgb(15 23 42 / 0.12);
  border-radius: 0.8em;
  background: #fff;
  box-shadow: 0 1em 2em -0.8em rgb(15 23 42 / 0.4);
  color: #475569;
  font: 400 0.8em/1.4 system-ui, sans-serif;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -0.5em);
  transition: opacity 0.2s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0.35s;
}
.tip-link-preview-img {
  flex: none;
  width: 6.5em;
  overflow: hidden;
  border-radius: 0.5em;
}
/* sky, sun, two mountain ridges and a lake: stand-ins for a real image */
.tip-link-preview-scene {
  position: relative;
  display: block;
  height: 100%;
  background:
    radial-gradient(circle at 70% 30%, #fde68a 0 0.6em, transparent 0.65em),
    linear-gradient(color-mix(in srgb, var(--c) 35%, #fff), #fff7ed);
  transform: scale(1.35);
  transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tip-link-preview-scene::before,
.tip-link-preview-scene::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
}
.tip-link-preview-scene::before {
  top: 38%;
  background: color-mix(in srgb, var(--c) 45%, #fff);
  clip-path: polygon(0 55%, 22% 12%, 42% 45%, 64% 0, 100% 48%, 100% 100%, 0 100%);
}
.tip-link-preview-scene::after {
  top: 55%;
  background: linear-gradient(color-mix(in srgb, var(--c) 70%, #0f172a) 62%, color-mix(in srgb, var(--c) 30%, #fff) 62%);
  clip-path: polygon(0 35%, 30% 0, 55% 40%, 78% 12%, 100% 38%, 100% 100%, 0 100%);
}
.tip-link-preview-text { padding: 0.15em 0; }
.tip-link-preview-text b {
  display: block;
  margin-bottom: 0.15em;
  color: #0f172a;
  font-size: 1.1em;
  font-weight: 700;
}
.tip-link-preview-text small {
  display: block;
  margin-top: 0.35em;
  color: var(--c);
  font-size: 0.85em;
  font-weight: 600;
}
.tip-link-preview:hover .tip-link-preview-tip,
.tip-link-preview:focus-within .tip-link-preview-tip {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.tip-link-preview:hover .tip-link-preview-scene,
.tip-link-preview:focus-within .tip-link-preview-scene { transform: scale(1); }

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

Customizing this snippet

  • Color: set --tip-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --tip-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 tooltips