AI CSS Animations

Range Slider Hover Tooltip

A volume slider that thickens its track, rings the thumb in a halo and pops a value bubble above it on hover. The fill and the thumb both read one --v percentage, so they always line up.

Also known as: range slider tooltip css, slider thumb hover, volume slider hover.

HTML

<div class="hfx-range-slider-tooltip" role="img" aria-label="Volume at 64 percent">
  <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 9.5v5h3.5L12 19V5L7.5 9.5zM15.5 9a4 4 0 0 1 0 6M18.5 6.5a7.5 7.5 0 0 1 0 11"/></svg>
  <span class="hfx-range-slider-tooltip-track"><span class="hfx-range-slider-tooltip-thumb" data-value="64"></span></span>
</div>

CSS

.hfx-range-slider-tooltip {
  --c: var(--hfx-color, #3b82f6);
  --v: 64%;
  font-size: var(--hfx-size, 16px);
  display: flex;
  align-items: center;
  gap: 0.9em;
  width: 16em;
  color: var(--c);
  font-family: system-ui, sans-serif;
}
.hfx-range-slider-tooltip > svg {
  flex: none;
  width: 1.35em;
  height: 1.35em;
}
.hfx-range-slider-tooltip-track {
  position: relative;
  flex: 1;
  height: 1.6em;
  cursor: pointer;
}
/* the visible bar: filled part, then the rest */
.hfx-range-slider-tooltip-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 0.4em;
  margin-top: -0.2em;
  border-radius: 99em;
  background: linear-gradient(90deg, var(--c) var(--v), color-mix(in srgb, var(--c) 22%, transparent) var(--v));
  transition: transform 0.25s ease;
}
.hfx-range-slider-tooltip-thumb {
  position: absolute;
  top: 50%;
  left: var(--v);
  width: 1.15em;
  height: 1.15em;
  margin: -0.575em 0 0 -0.575em;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0.2em var(--c), 0 0 0 0 color-mix(in srgb, var(--c) 20%, transparent), 0 0.15em 0.4em rgba(0, 0, 0, 0.3);
  transform: scale(0.8);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}
/* value bubble and its arrow */
.hfx-range-slider-tooltip-thumb::after,
.hfx-range-slider-tooltip-thumb::before {
  position: absolute;
  left: 50%;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-range-slider-tooltip-thumb::after {
  content: attr(data-value);
  bottom: calc(100% + 0.75em);
  min-width: 2.2em;
  padding: 0.3em 0.45em;
  border-radius: 0.45em;
  background: var(--c);
  color: #fff;
  font-size: 0.8em;
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, 0.5em) scale(0.6);
  transform-origin: 50% 100%;
}
.hfx-range-slider-tooltip-thumb::before {
  content: "";
  bottom: calc(100% + 0.35em);
  border: 0.3em solid transparent;
  border-top-color: var(--c);
  transform: translate(-50%, 0.5em);
}
.hfx-range-slider-tooltip:hover .hfx-range-slider-tooltip-track::before { transform: scaleY(1.5); }
.hfx-range-slider-tooltip:hover .hfx-range-slider-tooltip-thumb {
  transform: scale(1);
  box-shadow: 0 0 0 0.2em var(--c), 0 0 0 0.6em color-mix(in srgb, var(--c) 20%, transparent), 0 0.15em 0.4em rgba(0, 0, 0, 0.3);
}
.hfx-range-slider-tooltip:hover .hfx-range-slider-tooltip-thumb::after {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}
.hfx-range-slider-tooltip:hover .hfx-range-slider-tooltip-thumb::before {
  opacity: 1;
  transform: translate(-50%, 0);
}

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