Presets

Underline grow link animation

A link whose underline grows out from the left, center or right on hover.

CSSTailwindReactGIFMP4
00.000 / 0.350s
timing
style
content
24 max

npm i motion · the component uses motion/react

How it works

This link has no underline at rest; on hover a line grows out underneath the text from the left edge, the center or the right edge. It is the most common link hover on marketing sites and navigation bars because it adds feedback without changing the text.

The line is a separate element (aria-hidden) absolutely positioned at the bottom of the link, full width and Thickness pixels tall. It starts at transform: scaleX(0), which collapses it to nothing, and transitions to scaleX(1) on hover. The Grow from option sets transform-origin to left, center or right, which decides where the line starts. The link has 4px bottom padding to give the line room below the descenders.

Use left for body links and inline navigation, center for centered nav menus and tab bars, right for right-aligned or RTL layouts. Parameters: Label, Line color, Text color, Thickness, Grow from, Duration and Easing. Thickness of 1 to 2px matches body text; 3px suits bold headings. 0.3s with cubic-in-out keeps the line from feeling sluggish when users move quickly across a menu.

Since only transform changes, the effect never shifts surrounding text. The line spans the link box, so this approach suits single-line links; for links that wrap across lines use a background-image underline instead. Mirror the hover rule on :focus-visible so keyboard users see which link is focused.

How do I make the underline shrink toward the opposite side?

Use different origins for the two states: transform-origin right in the resting rule and left in the hover rule. The line then grows from the left on hover and retracts to the right when the pointer leaves, like a line passing through. This needs a small edit in the copied CSS because the preset uses one origin for both.

Does this work for links that wrap onto two lines?

Not well. The line is positioned under the whole inline-block box, so on a wrapped link it would sit under the bottom of the box only. For multi-line links, animate background-size of a linear-gradient background image from 0% to 100% instead; backgrounds follow each line fragment.

Why use a separate element instead of text-decoration?

text-decoration cannot be animated in length; you can only fade its color or change its offset. A separate element (or a ::after pseudo-element) can be scaled with transform, which runs on the compositor and lets you choose where the line starts. The exported code uses a span you can easily switch to a pseudo-element.

relatedMore like this

all hover effects →
01 Image zoom on hover hover
Card title Hover to lift this card.
02 Card lift on hover hover
03 Fill sweep button hover
Pro feature The border glows on hover.
04 Glow border on hover hover
05 Arrow nudge button hover

Export

format
height

480p max · small watermark · 3 per day · remove limits