AI CSS Animations

Right Tooltip With Arrow

An accent tooltip that springs out to the right of an icon button, scaling up from the tip of its arrow. transform-origin sits on the arrow point, so it grows out of the button.

Also known as: tooltip on the right css, scale tooltip animation, icon tooltip right side.

Filter by owner or date

HTML

<span class="tip-right-arrow">
  <button type="button" aria-label="Filters" aria-describedby="tip-right-arrow-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="M4 7h9m4 0h3M4 17h3m4 0h9"/><circle cx="15" cy="7" r="2"/><circle cx="9" cy="17" r="2"/></svg></button>
  <span class="tip-right-arrow-tip" id="tip-right-arrow-tip" role="tooltip">Filter by owner or date</span>
</span>

CSS

.tip-right-arrow {
  --c: var(--tip-color, #3b82f6);
  font-size: var(--tip-size, 16px);
  position: relative;
  display: inline-flex;
  margin-right: 10em; /* room for the tooltip in this preview */
}
.tip-right-arrow button {
  display: grid;
  place-items: center;
  width: 2.6em;
  height: 2.6em;
  padding: 0;
  border: 0;
  border-radius: 0.6em;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--c);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.tip-right-arrow svg {
  width: 1.25em;
  height: 1.25em;
}
.tip-right-arrow:hover button { background: color-mix(in srgb, var(--c) 24%, transparent); }
.tip-right-arrow button:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}
.tip-right-arrow-tip {
  position: absolute;
  top: 50%;
  left: calc(100% + 0.9em);
  z-index: 10;
  padding: 0.45em 0.75em;
  border-radius: 0.45em;
  background: var(--c);
  box-shadow: 0 0.4em 1em -0.4em color-mix(in srgb, var(--c) 90%, transparent);
  color: #fff;
  font: 600 0.85em/1.3 system-ui, sans-serif;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* scale from the arrow's point, which sits 0.5em left of the bubble */
  transform-origin: -0.5em 50%;
  transform: translateY(-50%) scale(0.3);
  transition: opacity 0.15s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.4s;
}
.tip-right-arrow-tip::before {
  content: "";
  position: absolute;
  top: 50%;
  right: calc(100% - 1px);
  width: 0.5em;
  height: 0.9em;
  background: inherit;
  clip-path: polygon(100% 0, 0 50%, 100% 100%);
  transform: translateY(-50%);
}
.tip-right-arrow:hover .tip-right-arrow-tip,
.tip-right-arrow:focus-within .tip-right-arrow-tip {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) scale(1);
}

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