AI CSS Animations

Dotted to Solid Underline Link Hover

A dotted underline whose dots stretch into dashes and close up into a solid line on hover. The dash length is a registered @property, so the gradient stop can transition.

Also known as: dotted underline css, dotted to solid underline, dashed underline hover.

HTML

<a class="hfx-link-dotted-underline" href="#">Terms of service</a>

CSS

@property --hfx-link-dotted-underline-dash {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 35%;
}
.hfx-link-dotted-underline {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  display: inline-block;
  color: var(--c);
  font: 600 calc(var(--hfx-size, 16px) * 1.25)/1.3 system-ui, sans-serif;
  text-decoration: none;
  --hfx-link-dotted-underline-dash: 35%;
  color: inherit;
  padding-bottom: 0.25em;
  background: linear-gradient(90deg, var(--c) var(--hfx-link-dotted-underline-dash), transparent 0) 0 100% / 0.32em 0.11em repeat-x;
  transition: --hfx-link-dotted-underline-dash 0.45s cubic-bezier(0.65, 0, 0.35, 1), color 0.3s ease;}
.hfx-link-dotted-underline:is(:hover, :focus-visible) {
  --hfx-link-dotted-underline-dash: 100%;
  color: var(--c);
}

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

Underline Grow Link
Underline from Center Link
Highlighter Link
Slide Up Text Link