Offline Indicators and Banners
What you'll learn: How to design clear, non-intrusive offline indicators that keep users informed without disrupting their experience.
Why Offline Indicators Matter
When your PWA goes offline, users need to know what's happening—but they don't need to be alarmed. Think of it like a subtle notification light on your router: it tells you the status without shouting. Your offline indicator should be visible enough to inform but subtle enough not to block critical UI or create panic.
Design Principles for Offline Indicators
Placement and Timing: Display your offline banner at the top or bottom of the viewport, never in the center where it blocks content. Show it immediately when navigator.onLine becomes false, and dismiss it gracefully when connectivity returns.
Visual Design: Use calm, informative colors (yellows or oranges rather than reds). Include a clear message like "You're offline—changes will sync when reconnected" rather than alarming text like "ERROR: NO CONNECTION!"
Non-Intrusive Behavior: The banner should not steal focus, force interaction, or cover interactive elements. Users should be able to continue browsing cached content uninterrupted.
Implementation Pattern
Building on your navigator.onLine detection skills, display a banner when offline:
window.addEventListener('offline', () => {
showOfflineBanner();
});
window.addEventListener('online', () => {
hideOfflineBanner();
});
function showOfflineBanner() {
const banner = document.getElementById('offline-banner');
banner.classList.add('visible');
}
Your banner might gracefully slide in from the top, persist as long as needed, and slide out when connection returns—all without requiring user dismissal.
Key Takeaway: Effective offline indicators balance visibility with subtlety, informing users of their connection state without interrupting their workflow or causing unnecessary concern.