Border field, CSS only
The same field with no JavaScript on the page. The outline morphs between its shapes with CSS alone, and the form is an ordinary form: the browser's own validation decides what's wrong. The JavaScript sandbox is still there; this is the other way to build it.
That doesn’t look like an email address yet.On its way. Check your inbox to confirm.
Type, leave it half done and click away, then send a good one. Sending reloads this page at #live-done, a hidden marker inside the form, and :target plays the burst. The marker has no box, so the page doesn't jump to it.
Every state
Held in place so they can be seen side by side. On a real page, typing and error come from the input, and loading and sent from an attribute the server sets.
Rest. A plain rounded box.
Typing. A soft cloud that breathes. It can't follow the caret.
Loading. data-state="loading": the wave runs round.
Error. :user-invalid: red teeth and a shake.
Sent. data-state="sent": a sunburst and the border as confetti, on a loop here.
CSS only, or JavaScript
| CSS only | With border-field.js | |
|---|---|---|
| Typing | A breathing cloud while there's text | A swell that follows the caret, nudged by each key |
| Error | :user-invalid, once the reader has touched the field | On send, and cleared as soon as it's fixed |
| Loading and sent | An attribute the page sets, or a hidden :target marker after a normal submit | Driven by your onSubmit |
| Morphing | Chrome, Edge and Firefox morph the line. Safari cross-fades between shapes. | Every browser |
| Width | Drawn for one size and stretched, so the waves widen on wide fields | Fits any size |
| Settings | Edit and rerun pnpm forms:css | Live, and in the sandbox |