Someone spends twenty minutes filling in a claim, a quote, or a long support request. They step away to find a reference number. When they come back and press submit, the application shows a sign-in screen, and the form is empty after they log in.
The security team did not intend that outcome, and neither did the designers. It happens because session expiry is usually configured as a server setting and never designed as a moment the user lives through. This guide covers how to treat it as part of the interface.

Photo by Suki Lee on Pexels
Know which clocks are actually running
Most applications have more than one timer, and confusion between them causes the worst surprises. An idle timeout ends a session after a period with no activity. An absolute timeout ends it after a fixed lifetime, however busy the person has been.
Tokens add a third clock. A short-lived access token may expire every few minutes while a refresh token keeps the session alive behind the scenes. An identity provider may hold its own single sign-on session with different limits again.
Infrastructure can add a fourth. Proxies, load balancers and cache stores often have expiry settings that nobody thinks of as user-facing. If the session store evicts records early under memory pressure, the interface will promise time that does not exist.
Write all of these down in one table before designing anything. For each, record the duration, what resets it, and what the user sees when it ends. The shortest effective limit is the one your warning has to describe.
Choose durations from risk, then explain them
A timeout is a security control. It limits how long an unattended browser or a stolen session identifier stays useful. The OWASP Session Management Cheat Sheet describes common idle ranges of 2 to 5 minutes for high-value applications and 15 to 30 minutes for lower risk ones.
Treat those as a starting point for a conversation, not a default to paste in. A screen showing payment controls on a shared warehouse terminal deserves a different limit from a long-form editor on a personal laptop. One application can reasonably apply a short limit to sensitive actions and a longer one to drafting.
Check whether you are bound by a standard, a contract or a regulator. The NIST Digital Identity Guidelines set out reauthentication expectations by assurance level, and many procurement questionnaires refer to them.
Then ask what the work looks like. If a typical task takes 25 minutes and includes looking things up elsewhere, a 15 minute idle limit will fail honest users every day. Either lengthen it, or make sure nothing is lost when it fires.
Meet the accessibility requirement first
People who read slowly, use a screen reader, rely on switch input or get interrupted often are hit hardest by time limits. WCAG success criterion 2.2.1, Timing Adjustable, is the baseline most teams work from.
It offers several routes. A user can turn the limit off or lengthen it substantially in advance. Alternatively, they are warned before time runs out, given at least 20 seconds to extend it with a simple action, and allowed to extend it at least ten times.
There are exceptions for limits that are essential, tied to real-time events, or longer than 20 hours. Do not assume your case qualifies because a security policy mentions a number. Document the reasoning if you rely on an exception.
Stricter criteria are worth borrowing even if you are not formally targeting them. Telling people about inactivity limits at the start, and letting them resume after signing in again with their data intact, removes most of the harm.

Photo by Wolf Art on Pexels
Time the warning around real behaviour
A warning that appears 20 seconds before logout technically exists and practically fails. Someone looking at a paper document will miss it. For most business applications, showing it two to five minutes ahead gives a person time to notice and react.
Scale the lead time to the session length. A five minute banking session cannot warn at five minutes remaining. A two hour editing session can afford a quiet notice early and a more prominent one near the end.
Do not use the warning as a countdown that appears on every page from the start. A permanent timer creates anxiety and trains people to ignore it. Show nothing until there is a decision to make.
Where a hard limit exists and cannot be extended, say so earlier and differently. "You will need to sign in again at 4:30 PM. Your draft is saved." is honest and calm. A button labelled "Stay signed in" that cannot work is neither.
Write a dialog that answers three questions
A good warning tells the person what is about to happen, when, and what they can do. Put the primary action first and make it obvious. "Stay signed in" is clearer than "OK" or "Continue".
Offer a second action to sign out now, which matters on shared computers. Avoid making dismissal ambiguous. If closing the dialog extends the session, state that. If it does not, keep the countdown visible somewhere.
Say what happens to unsaved work. This is the question people are actually worried about. If drafts are preserved, say so in one sentence. If they are not, be direct and offer a save button.
Build it as a real modal alert. The WAI-ARIA alert dialog pattern covers roles, labelling and focus movement. Move focus into the dialog when it opens and return it to the previous field when it closes, so typing can resume where it stopped.
Announce time sparingly. A live region that reads every passing second makes a screen reader unusable. Announce when the dialog opens, then at a few meaningful points such as one minute and twenty seconds.
Keep every tab in agreement
Many people work with the same application open in several tabs. If each tab runs its own idle timer, a background tab can log out someone who is actively typing in the foreground one.
Share activity between tabs. The Broadcast Channel API lets pages on the same origin send each other messages, so one extension closes the warning everywhere. A storage event listener is an older alternative.
const channel = new BroadcastChannel('session');
async function extendSession() {
const res = await fetch('/session/extend', { method: 'POST' });
if (!res.ok) return showSignInDialog();
const { expiresAt, serverNow } = await res.json();
applyExpiry(expiresAt, serverNow);
channel.postMessage({ expiresAt, serverNow });
}
channel.onmessage = ({ data }) => {
applyExpiry(data.expiresAt, data.serverNow);
};
Notice that the expiry comes from the server. The client clock may be wrong, and a decremented counter drifts badly when a browser throttles timers in hidden tabs or a laptop sleeps.
Compute remaining time from a deadline each time you draw it, and recheck with the server when a tab becomes visible again. A machine waking after an hour should show an expired state immediately, not a countdown with eight minutes on it.
Be careful about what counts as activity. Background polling should not keep a session alive forever, or the idle timeout stops meaning anything. Count deliberate input, throttle the pings, and mark automated requests so the server can ignore them.

Photo by Caleb Oquendo on Pexels
Protect the work before the clock runs out
The warning is a courtesy. Saving the work is the safety net, because some people will always miss the dialog.
Autosave drafts to the server at sensible intervals and when fields lose focus. Keep a draft separate from a submitted record so partial data never enters downstream processes. Show a quiet "Saved" indicator with a time so people can trust it.
Local browser storage is useful as a fallback when a save fails, but think about shared devices. Sensitive values such as card numbers, health details or government identifiers should not be written there. Clear local drafts after a successful submit and on explicit sign-out.
Plan for conflicts too. If the same draft was edited on another device while this tab slept, do not overwrite it silently. Compare versions and let the person choose.
Make signing back in a detour, not a restart
When the session has expired, keep the page on screen where policy allows and ask the person to authenticate in a dialog or a separate window. Once they succeed, retry the failed request and carry on.
If the page contains sensitive information, hide or remove it at expiry while holding the draft on the server. After sign-in, restore the same route, the same step and the same values.
Check that the returning user is the same account. On a shared terminal, the next person must never inherit the previous person's draft. Key drafts to the account identifier and discard in-memory state when it differs.
Handle requests made after expiry consistently. An API should return a clear unauthorized status, and the client should queue the action instead of redirecting mid-save. Redirects that swallow a POST body are the classic source of vanished forms.
"People forgive being asked to sign in again. What they remember is the half hour of typing that disappeared, so we design the recovery before we argue about the number of minutes." - Dennis Traina, founder of 137Foundry
Test it the way it will happen
Add a setting in test environments that shortens every limit to a minute or two. Nobody will test a 30 minute flow repeatedly by waiting.
Walk through the awkward cases: two tabs, a sleeping laptop, a lost network at the moment of extension, a file upload longer than the idle limit, and expiry while a confirmation dialog is already open. Run the flow with a keyboard only and with a screen reader.
Then watch production. Count warnings shown, sessions extended, expiries and drafts restored. A high rate of expiry on one page usually means the task takes longer than the limit allows. Our teams often find this during web development work on older portals, where the timeout was set years before the longest form was added.
If your application is signing people out in the middle of real tasks, our web development services cover the session logic, the dialog and the draft handling together. You can see the wider range of services or start at the 137Foundry homepage.