StealThis .dev

Form — Autosave + saved indicator + restore

A Google Docs style note editor that quietly saves itself as you write. Edits are debounced, then persisted to localStorage while a status pill cycles from Unsaved changes to Saving to Saved a moment ago, announced through an aria-live region. A Save now button forces an immediate write, a live word and character count tracks length, and reopening the page offers to restore any unfinished draft. Validation gates Publish, which clears the saved draft from the device.

Open in Lab
html css vanilla-js
Targets: JS HTML

Code

Autosave + saved indicator + restore

A long-form note editor with a title field and a roomy textarea that saves your work without you ever pressing a button. As you type, a status pill in the header moves through three states — an amber “Unsaved changes” the moment you edit, a pulsing “Saving…” once the debounce timer fires, and a calm green “Saved just now” when the write lands. The pill is wrapped in an aria-live="polite" region, so screen readers hear each transition without it stealing focus, and the relative timestamp keeps refreshing so “Saved a moment ago” ages into “Saved 2 minutes ago” on its own.

Drafts are written to localStorage on a debounced cadence, with a manual “Save now” button for impatient moments and a beforeunload flush so an in-flight edit is never lost if you close the tab mid-keystroke. Reopen the editor with an unfinished draft on the device and a focus-trapped restore banner appears — “Restore unsaved draft?” — letting you bring the content back or discard it, with Escape to dismiss. A live word and character count sits beside the note label, and publishing runs real validation (a title is required, the body needs a few characters) before clearing the stored draft and confirming with a toast.

Every state change is reflected both visually and for assistive tech: invalid fields get aria-invalid, error helper text switches to role="alert", focus moves to the first problem on a blocked publish, and a small toast helper announces saves, restores, and discards. The layout is a single centered card that stacks cleanly down to 360px, with visible focus rings throughout and a prefers-reduced-motion fallback.