The simplest JavaScript library to apply light - dark theme in your website.
First Check Out One Example
Files
- index.html
- style.css
- test.js
<!DOCTYPE html>
<html lang="en">
<head>
<script src="./test.js" type="module" defer></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello World</h1>
<button class="btn">Toggle Button 1</button>
<button class="btn">Toggle Button 2</button>
<p>Auto -- Light -- Dark</p>
</body>
</html>
body {
background-color: var(--bg);
color: var(--text);
}
import themeChanger from "https://codeabinash.github.io/theme-changer.js/index.js";
let theme = new themeChanger({
selector : '.btn',
theme: {
light:
`--bg : #ddd;
--text: #555;`,
dark:
`--text: #eee;
--bg: #222;`
}
})
Check The example from here : https://codeabinash.github.io/theme-changer.js/test/
let theme = new themeChanger({
selector : '.btn', // css selector (internally querySelectorAll)
theme: {
light: // css code
`--bg : #ddd;
--text: #555;`,
dark: // css code
`--text: #eee;
--bg: #222;`
}
})
let theme = new themeChanger({
theme: {
light: 'CSS code for light theme',
dark: 'CSS code for dark theme';
}
})
theme.getCurrentTheme()
// returns 'light' or 'dark'
theme.getTheme()
// returns 'Light' or 'Dark' or 'Auto'
theme.toggle()
// toggles theme as auto - light - dark
theme.applyAutoMode()
// applies auto mode
theme.applyLightMode()
// applies light mode
theme.applyDarkMode()
// applies dark mode
npm i theme-changer-light-dark