Underline Animation
A bare field with a grey underline: step into it and an indigo line starts from the middle and reaches both ends in 0.3 s. The line belongs to the container, so it stays as long as focus is inside the group.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Forms has 21 effects, including 2 free. Explore the category →
3 usage examples



How it works
The .udn-input field has no frame and no fill, only a 2 px grey bottom border. The coloured line is not a tag: it is the ::after pseudo-element of the .udn-field container, laid on the same line, 0 wide and placed at left: 50%.
The .udn-field:focus-within::after rule brings it to left: 0 and width: 100%. Both values change together in 0.3 s, so the line seems to open from the centre. On the way out it closes back towards the middle the same way.
:focus-within does not only watch the field: any element of the container that takes focus keeps the line on. Put a button next to the field, inside .udn-field, and the line underlines both while you move from one to the other (measured: a 280 px line with focus on the button).
There is no label that moves up. As shipped, the field says what it expects through its placeholder, which the browser clears at the first letter. The .fx-0292-root root brings the dark demo background and the box-sizing.
Accessibility
- Field name: it comes from
aria-label="Your name"; the identical grey text is only a hint, and it goes away as soon as you type. Keep the effect as is for a field whose meaning is obvious, or give it a visible caption as in the mail example. - Hint colour: the effect sets it itself to
#a1a1aa(7.7:1 on the demo background). Without that rule each browser picked its own grey, and Chromium's dropped to 4.3:1. - Lines: the resting underline is pale (white at 20%, 1.8:1); the active line, indigo, reaches 4.4:1. On your own background, tune
--udn-lineand--udn-accentto keep at least 3:1 on the active line. - Keyboard: Tab is enough, the line is drawn when focus arrives wherever it comes from (click, tap, Tab,
focus()). No other focus cue is drawn on the field: the line is that cue. - System-imposed colours: in high-contrast mode, the line takes the system's selection colour.
- Reduced motion: the line appears and disappears at once, without stretching.
- Touch: 44 px tall, 16 px text.
Browser compatibility
:focus-within sets the floor: Chrome 60, Firefox 52, Safari 10.1 (@mdn/browser-compat-data); ::placeholder and CSS variables are older. Run on 04/12/2026 in Chromium 149, Firefox 151 and WebKit 26.5: two instances on the page (typing in the second, the first one's line at 0 px), container written as a <label>, focus on a button of the group, 390 px touch screen, reduced motion, forced colours in Chromium and Firefox.
Without :focus-within the coloured line is never drawn: what remains is a grey-underlined field, usable, with no visual feedback on focus. No JavaScript is loaded.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0292-root">
<div class="udn-field">
<input class="udn-input" type="text" name="name" autocomplete="name" aria-label="Your name" placeholder="Your name">
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Width (CSS — --udn-width) |
280px | Width of the container, hence of the line. 100% to follow the column. |
Active line colour (CSS — --udn-accent) |
#6366f1 | A solid colour. For a gradient, write it straight into the background of .udn-field::after. |
Resting underline (CSS — --udn-line) |
white at 20% | transparent if you draw the line yourself under a group wider than the field. |
Texts (CSS — --udn-text, --udn-muted, --udn-font-size) |
#fff · #a1a1aa · 1rem | Typed value, hint text, size. On a light background, darken both colours. |
Where the line starts (CSS — left: 50% in .udn-field::after) |
the middle | left: 0 makes it start from the left; left: auto; right: 0 from the right (then remove the left: 0 of the :focus-within rule). |
Thickness and duration (CSS — height, border-bottom, transition) |
2px · 0.3 s | Change the thickness in both places so the line covers the grey one exactly. |
Caption (HTML — aria-label, placeholder) |
Your name | The two texts go together: translate them together, or replace them with a visible <label>. |
FAQ
<label> and put the caption inside: <label class="udn-field" style="display:flex;align-items:center;gap:12px"><span>Subject</span><input class="udn-input" type="text" name="subject"></label>. Then remove aria-label and placeholder. The line will underline the caption and the field together..udn-field: the line follows the focus of the whole container. This is intended for a field that comes with − and + buttons or a clear cross. If the button should not count, move it out of the container.