Automatic dark mode generation for pages without custom dark mode CSS. Perfect for page builders and dynamic content.
Universal Dark Mode automatically transforms any page to dark mode by analyzing computed colors and applying intelligent transformations.
Include the scripts in this order:
<!-- Required: Color manipulation utilities -->
<script src="javascript/color-adjuster.js"></script>
<!-- Required: Theme toggle functionality -->
<script src="javascript/theme-toggle.js"></script>
<!-- Universal Dark Mode -->
<script src="javascript/universal-dark-mode.js"></script>
Uses HSP algorithm to detect light vs dark colors
Transforms CSS gradients color by color
Preserves info, success, warning, error hues
Restores original styles on theme switch
MutationObserver handles new elements
Skip elements with data-no-dark-mode
data-theme attribute changes on <html>backgroundColor, backgroundImage, color, and borderColorHuman Sensitivity Poo (HSP) accounts for how humans perceive color brightness:
HSP = sqrt(0.299 * R² + 0.587 * G² + 0.114 * B²)
// If HSP > 127.5 → color is "light"
// If HSP ≤ 127.5 → color is "dark"
Add data-no-dark-mode to any element to exclude it (and its children) from transformation:
<div data-no-dark-mode>
<!-- This stays as-is in dark mode -->
<p style="background: yellow; color: black;">
I won't be transformed!
</p>
</div>
| Method | Description |
|---|---|
RSL.UniversalDarkMode.init() |
Initialize the module (called automatically) |
RSL.UniversalDarkMode.refresh() |
Force re-scan and re-transform all elements |
RSL.UniversalDarkMode.destroy() |
Remove all transformations and clean up |
RSL.UniversalDarkMode.setColors(obj) |
Customize the dark mode color palette |
RSL.UniversalDarkMode.getColors() |
Get the current color palette |
RSL.UniversalDarkMode.setColors({
bgDark: '#0d1117', // GitHub-style dark
bgDarkSecondary: '#161b22',
textLight: '#c9d1d9',
textLightSecondary: '#8b949e'
});
[data-theme="dark"] CSS rules instead.