Dark Mode
Set the default Light/Dark mode for your app. The Auto mode follows the device setting for Light & Dark Mode, but you can set Light or Dark to force a mode irrespective of the device setting. The current mode can also be changed at runtime using the Median JavaScript Bridge.
Select whether the native UI elements within your app such as the top nav menu, sidebar nav menu, bottom tab menu are always set to Dark Mode or if they follow the active device mode for Light & Dark (Auto mode).
You may add support for dark and light modes within your web content by making use of the perfers-color-scheme
CSS media query. Your app sets this parameter to light
and dark
based on the current device mode, and will change it dynamically when the device mode changes.
You may add a control toggle within your web content to force Light or Dark mode in addition to following the device setting (Auto mode).
↔️Median JavaScript Bridge
// Force Light Mode // Always use Light styling irrespective of device mode if (navigator.userAgent.indexOf('median') > -1) { median.screen.setMode({'mode': 'light'}); } // Force Dark Mode // Always use Dark styling irrespective of device mode if (navigator.userAgent.indexOf('median') > -1) { median.screen.setMode({'mode': 'dark'}); } // Auto Mode // Set to Auto mode to follow the device mode (Light or Dark) if (navigator.userAgent.indexOf('median') > -1) { median.screen.setMode({'mode': 'auto'}); } // Revert to Default // Revert to the default configuration set in the app (Light/Dark/Auto) if (navigator.userAgent.indexOf('median') > -1) { median.screen.setMode({'mode': 'default'}); }
We recommend using CSS variables to define the desired colors in Light mode versus Dark mode. And we suggest setting a cookie when the user manually selects Light or Dark mode rather than Auto.
For a live example that you can adapt for your own website check out Median's Dark Mode Switcher Codepen Example or refer to this comprehensive guide from CSS-Tricks that provides helpful details and examples for implementing dark mode using CSS.
Updated about 2 months ago