What’s the Deal with Dialogs These Days?
Remember when we had to deal with those ugly, basic alert(), confirm(), and prompt() boxes that looked like they were designed in 1995? Yeah, those days are long gone. In 2025, we’ve got some seriously cool options that’ll make your users actually enjoy getting notifications instead of wanting to throw their computer out the window.
The Browser’s Built-in Goodies
1. HTML Dialog Element
The New Kid That Actually Made It
The <dialog> element is like that quiet kid in class who suddenly became really popular. It’s now the go-to choice for creating modals that don’t suck:
|
1 2 3 4 5 6 7 |
// Basic usage const dialog = document.querySelector('dialog'); dialog.showModal(); // Opens as modal with backdrop dialog.show(); // Opens as non-modal dialog.close(); // Closes the dialog |
Why It’s Actually Good:
- Accessibility works out of the box (finally!)
- Handles focus management so you don’t have to
- Built-in backdrop that looks decent
- Events that actually make sense
2. Notification API
For When You Need to Annoy Users Outside the Browser
This lets your web page send notifications to the user’s desktop or phone, even when they’re not looking at your site:
|
1 2 3 4 5 6 7 8 9 10 |
// Request permission and show notification if (Notification.permission === 'granted') { new Notification('Hello!', { body: 'This is a system notification', icon: '/icon.png', vibrate: [200, 100, 200] }); } |
What’s New in 2025:
- You can’t just spam users anymore (browsers got smart)
- Rich media support because apparently text wasn’t enough
- Better mobile integration that doesn’t drain batteries
3. Push API with Service Workers
The Stalker Feature Everyone Actually Wants
This is how you send notifications even when your app is completely closed. It’s like having a personal assistant that never sleeps:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Service worker registration for push notifications self.addEventListener('push', event => { const options = { body: event.data.text(), icon: '/icon.png', badge: '/badge.png', vibrate: [100, 50, 100], data: { dateOfArrival: Date.now() } }; event.waitUntil( self.registration.showNotification('Push Message', options) ); }); |
The Libraries That Don’t Suck
1. SweetAlert2 – The Undisputed Champion
URL: https://sweetalert2.github.io/
Why Everyone Uses It: Because it makes dialogs that don’t look like they’re from Windows 98
This thing completely replaced the native JavaScript dialogs and nobody misses the old ones.
What Makes It Great:
- Looks gorgeous without you having to do anything
- Actually works with screen readers (accessibility win!)
- Tons of customization options
- Smooth animations that don’t make users nauseous
- Works with any design system
Usage:
|
1 2 3 4 5 6 7 8 9 |
Swal.fire({ title: 'Are you sure?', text: "You won't be able to revert this!", icon: 'warning', showCancelButton: true, confirmButtonText: 'Yes, delete it!' }); |
2. The Other Options (For When You’re Feeling Adventurous)
- Headless UI: For people who like to style everything themselves
- Dialog Polyfill: When you still have to support Internet Explorer (RIP)
- Micromodal: Tiny and efficient at 2.8KB
Toast Notifications That Actually Toast
1. Notyf – Small But Mighty
URL: https://carlosroso.com/notyf/
Size: Only 3KB (your users’ bandwidth will thank you)
Why It’s Cool: Works everywhere, looks good, and doesn’t break accessibility
|
1 2 3 4 5 |
const notyf = new Notyf(); notyf.success('Your changes have been saved!'); notyf.error('Please fill out all required fields'); |
2. Toastify
URL: https://apvarun.github.io/toastify-js/
The Deal: Pure JavaScript, stackable notifications, and you can put them anywhere on the screen
|
1 2 3 4 5 6 7 8 |
Toastify({ text: "This is a toast", duration: 3000, gravity: "top", position: "right" }).showToast(); |
3. Framework-Specific Stuff (Because Everyone Has Opinions)
For React People:
- React Hot Toast: The new hotness, literally – https://react-hot-toast.com/
- React Toastify: The reliable old friend with tons of features – npm package
For Vue Enthusiasts:
- Vue Toastification: Works with Vue 3, which is nice
- Vue Notification: Simple and gets the job done
For Angular Warriors:
- NGX Toastr: Popular choice that plays well with Angular
- Angular Material Snackbar: If you’re already in the Material Design ecosystem
What’s Trending in 2025 (The Cool Kids’ Features)
Rich Media Notifications
Gone are the days of boring text-only notifications. Now you can throw in:
- Images and GIFs: Because everything needs to be visual now
- Videos: For when you really want someone’s attention
- Interactive buttons: Let users do stuff without opening your app
- Custom layouts: Make it look exactly how your designer envisioned
AI-Powered Personalization
The robots are taking over notification timing too:
- Smart timing: AI figures out when users actually want to be bothered
- Content personalization: Messages that adapt to what users actually care about
- User behavior analysis: Learning when to back off with the notifications
- Predictive engagement: Knowing what users want before they do
Enhanced Accessibility (Finally!)
We’re actually making things usable for everyone:
- Screen reader optimization: Works properly with assistive technology
- High contrast modes: Visible even when everything else isn’t
- Reduced motion options: Respects when users don’t want things bouncing around
- Keyboard navigation: Everything works without a mouse
Mobile-First Design (Because Everyone’s on Their Phone)
- Touch-friendly interfaces: Buttons you can actually tap without missing
- Gesture support: Swipe to dismiss like you’re on Tinder
- Responsive layouts: Looks good on everything from phones to TVs
- Battery optimization: Won’t kill your phone in 20 minutes
Browser Support (Or: Which Browsers Actually Work)
Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
HTML Dialog | Works since 37 | Works since 98 | Works since 15.4 | Works since 79 |
Notification API | Works since 22 | Works since 22 | Works since 7 | Works since 14 |
Push API | Works since 42 | Works since 44 | Works since 16 | Works since 17 |
Service Workers | Works since 40 | Works since 44 | Works since 11.1 | Works since 17 |
Translation: If your users are on anything remotely modern, you’re good to go.
How to Not Mess This Up (Best Practices)
User Experience Guidelines
- Don’t be annoying: Only ask for notification permissions when it makes sense
- Explain yourself: Tell users why they’d want your notifications
- Respect boundaries: If someone says no to notifications, respect that
- Have backup plans: Not everyone’s on the latest browser
- Test with real people: Make sure screen readers actually work
Performance Tips
- Keep it light: Choose libraries that won’t slow down your site
- Load when needed: Don’t load notification code until someone might use it
- Optimize service workers: Background scripts should be efficient
- Clean up: Remove event listeners when you’re done with them
Security and Privacy (The Boring But Important Stuff)
- HTTPS only: Most of these APIs require secure connections
- Check permissions: Don’t assume you still have permission
- Minimize data: Don’t send sensitive info in notifications
- Easy opt-out: Make it simple for users to turn off notifications
The Bottom Line
Notifications and dialogs in 2025 are actually pretty great. The native browser APIs work well enough for basic stuff, but if you want something that looks professional and doesn’t make users want to uninstall your app, go with the modern libraries.
SweetAlert2 is basically the standard for dialogs at this point, and for toast notifications, you can’t go wrong with Notyf if you want something small or Toastify if you need more features.
The trend toward rich media and AI personalization is real, but don’t get too fancy unless your users actually want that. Sometimes a simple “Your file was saved” message is exactly what people need.
Just remember: the best notification is often no notification at all. Use them wisely.
FAQ
What are JavaScript notifications and how do they work?
How do I request notification permissions from users?
Notification.requestPermission() method to request permission. This method returns a Promise that resolves to ‘granted’, ‘denied’, or ‘default’. Users must explicitly grant permission before notifications can be displayed. Best practice is to request permission only in response to user interaction, like clicking a button.
|
1 2 3 4 5 6 7 8 9 |
Notification.requestPermission().then(function(permission) { if (permission === 'granted') { console.log('Notification permission granted.'); } else { console.log('Unable to get permission to notify.'); } }); |
Why do my JavaScript notifications require HTTPS?
How do I create and display a notification?
|
1 2 3 4 5 6 7 8 9 10 11 |
// Simple notification const notification = new Notification('Hello!'); // Notification with options const notification = new Notification('New Message', { body: 'You have received a new message', icon: '/images/notification-icon.png', tag: 'message-notification' }); |
What are Service Workers and why are they needed for push notifications?
showNotification() method, enabling re-engagement of users when they’re not actively using the app.Which browsers support JavaScript notifications?
Why isn’t my Notification.requestPermission() showing a permission prompt?
- The user previously denied permission and browsers remember this choice
- The request wasn’t triggered by user interaction (browsers block automatic requests)
- The site is not using HTTPS
- The user has ignored permission prompts multiple times, causing browsers to automatically block future requests
How do I handle notification clicks and events?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
const notification = new Notification('Click me!', { body: 'This notification is interactive' }); notification.onclick = function(event) { console.log('Notification clicked'); window.focus(); // Focus the browser window this.close(); // Close the notification }; notification.onclose = function(event) { console.log('Notification closed'); }; |
What’s the difference between local notifications and push notifications?
How do I set up push notifications with Firebase Cloud Messaging (FCM)?
- Register a service worker
- Initialize FCM in your app with API keys
- Request notification permissions
- Subscribe to FCM using
pushManager.subscribe() - Send the subscription endpoint to your server
- Handle incoming push events in the service worker
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// In your service worker self.addEventListener('push', function(event) { const options = { body: event.data.text(), icon: '/images/icon.png', badge: '/images/badge.png' }; event.waitUntil( self.registration.showNotification('Push Notification', options) ); }); |
Why do my notifications show “default” permission status but no prompt appears?
- You’re in a Progressive Web App (PWA) context where different permission rules apply
- The browser has blocked permission requests due to user behavior patterns
- There are issues with the service worker registration
- Mobile browsers (especially on Android 13+) have stricter permission policies
How do I check if notifications are supported in the browser?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function checkNotificationSupport() { if (!('Notification' in window)) { alert('This browser does not support desktop notification'); return false; } if (!('serviceWorker' in navigator)) { console.log('Service Worker not supported'); return false; } return true; } |
What are the best practices for implementing JavaScript notifications?
- Only request permission in response to user actions
- Provide clear value proposition before asking for permissions
- Don’t overwhelm users with too many notifications
- Make notifications relevant and personalized
- Use appropriate timing for requests
- Handle all permission states gracefully
- Test across different browsers and devices
- Respect user preferences and provide easy opt-out options
How do I troubleshoot notification issues in production?
- Check browser console for errors
- Verify HTTPS is properly configured
- Confirm service worker is registered and active
- Test permission status with
Notification.permission - Check if notifications are blocked in browser settings
- Verify push subscription is valid
- Test in different browsers and devices
- Use browser developer tools to inspect service worker status and push events
Can I customize the appearance of JavaScript notifications?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
const options = { body: 'Notification body text', icon: '/icons/notification.png', image: '/images/notification-image.jpg', badge: '/icons/badge.png', vibrate: [200, 100, 200], actions: [ {action: 'view', title: 'View'}, {action: 'close', title: 'Close'} ], tag: 'unique-tag' }; new Notification('Custom Notification', options); |
Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.
and let’s create something amazing together!
RELATED POSTS
Or: How I Learned to Stop Worrying and Love the Underscore Remember when you could just tell your computer what to do, in plain English, and it would actually do it? No? Well, grab your DeLorean, because we’re going back to the future with _hyperscript (yes, that underscore is part of the name, and yes, […]
So you want better conversion rates from your email campaigns? Great news – I am trying to summarize conversion strategies that don’t require a PhD in marketing, design tricks that actually matter, how to play nice with social media, when to hit send, and the mysterious image-to-text ratio that could be tanking your deliverability. More […]
As Visual Studio Code continues to dominate the code editor landscape in 2025, developers working with remote servers face an important decision: which SFTP extension should they use? The marketplace offers numerous options, but not all extensions are created equal. Some have been abandoned by their maintainers, while others have evolved into robust, actively maintained […]
Alexander
I am a full-stack developer. My expertise include:
- Server, Network and Hosting Environments
- Data Modeling / Import / Export
- Business Logic
- API Layer / Action layer / MVC
- User Interfaces
- User Experience
- Understand what the customer and the business needs
I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.
With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.
Beyond technology, I value peace and surround myself with like-minded individuals.
I firmly believe in the principle: Help others, and help will find its way back to you when you need it.
.highlights
PORTALZINE® NMN
Alexander Gräf
Stettiner Str. Nord 20
DE-49624 Löningen
