Toast Timing and Auto-Dismiss
You'll learn how to set appropriate display durations for toast notifications and when to provide manual dismiss controls.
When you show a toast notification, it shouldn't linger forever or vanish before users can read it. The core challenge is balancing automatic dismissal with readability—like subtitles on a video that disappear after you've had time to read them, but not so quickly that you miss important words.
Display Duration Guidelines
The standard rule of thumb: 3–5 seconds for short messages, longer for messages with more text. A common formula is:
- Success/Info toasts: 3–4 seconds (quick confirmation)
- Warning toasts: 5–6 seconds (needs attention)
- Error toasts: 7–10 seconds or manual-only (critical info)
You can also calculate dynamically: base time + (word_count × 200ms) gives users roughly 200 milliseconds per word to read comfortably.
function calculateToastDuration(message) {
const wordCount = message.split(' ').length;
const baseTime = 3000; // 3 seconds minimum
const timePerWord = 200; // ms
return Math.min(baseTime + (wordCount * timePerWord), 10000); // cap at 10s
}
Manual Dismiss Options
For error messages or complex information, always provide a close button. Users should control when they've finished reading critical content. Info and success toasts can auto-dismiss safely, but errors should often stay until explicitly dismissed—you don't want "Payment failed: card declined" vanishing before someone reads it.
Think of auto-dismiss for good news, manual dismiss for problems.
Key Takeaway: Match toast duration to message importance and length—auto-dismiss simple confirmations after 3–5 seconds, but let users manually dismiss errors and warnings when they're ready.