AI CSS Animations

Tooltip With Delay

Waits half a second before showing, so passing the cursor over the button never flashes it, and hides at once. A thin bar under the button fills while you wait.

Also known as: tooltip hover delay css, hover intent tooltip, transition delay tooltip.

Ships main to production

HTML

<span class="tip-hover-delay">
  <button type="button" aria-describedby="tip-hover-delay-tip"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 15c-1.5 1.5-2 4.5-2 4.5s3-.5 4.5-2"/><path d="M9.5 17.5 6.5 14.5C8 9 12 4.5 19.5 4.5c0 7.5-4.5 11.5-10 13z"/><circle cx="14.5" cy="9.5" r="1.5"/></svg>Deploy</button>
  <span class="tip-hover-delay-tip" id="tip-hover-delay-tip" role="tooltip">Ships main to production</span>
</span>

CSS

.tip-hover-delay {
  --c: var(--tip-color, #3b82f6);
  font-size: var(--tip-size, 16px);
  position: relative;
  display: inline-flex;
}
.tip-hover-delay button {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.6em 1.2em;
  border: 0;
  border-radius: 0.5em;
  background: var(--c);
  color: #fff;
  font: 600 1em system-ui, sans-serif;
  cursor: pointer;
}
.tip-hover-delay svg {
  width: 1.2em;
  height: 1.2em;
}
.tip-hover-delay button:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}
/* the wait bar: fills over the same 0.5s the tooltip waits */
.tip-hover-delay::after {
  content: "";
  position: absolute;
  top: calc(100% + 0.4em);
  left: 0.5em;
  right: 0.5em;
  height: 0.18em;
  border-radius: 1em;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.15s ease;
}
.tip-hover-delay-tip {
  position: absolute;
  bottom: calc(100% + 0.7em);
  left: 50%;
  z-index: 10;
  padding: 0.45em 0.8em;
  border-radius: 0.45em;
  background: color-mix(in srgb, var(--c) 14%, #0f172a);
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.07), 0 0.5em 1em -0.4em rgb(0 0 0 / 0.5);
  color: #fff;
  font: 500 0.85em/1.3 system-ui, sans-serif;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 0.3em);
  /* hiding: immediate */
  transition: opacity 0.1s ease, transform 0.1s ease, visibility 0s 0.1s;
}
.tip-hover-delay-tip::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 0.6em;
  height: 0.6em;
  background: inherit;
  transform: translate(-50%, -50%) rotate(45deg);
}
.tip-hover-delay:hover::after,
.tip-hover-delay:focus-within::after {
  transform: scaleX(1);
  transition: transform 0.5s linear;
}
/* showing: after a 0.5s delay */
.tip-hover-delay:hover .tip-hover-delay-tip,
.tip-hover-delay:focus-within .tip-hover-delay-tip {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity 0.2s ease 0.5s, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) 0.5s, visibility 0s 0.5s;
}

@media (prefers-reduced-motion: reduce) {
  .tip-hover-delay, .tip-hover-delay *, .tip-hover-delay::before, .tip-hover-delay::after, .tip-hover-delay *::before, .tip-hover-delay *::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