Dark and Light Theme Switcher in CSS


Create a theme switcher to toggle between dark and light themes using CSS variables and JavaScript.

Source Code

:root {
    --background-color: #fff;
    --text-color: #000;
}
[data-theme="dark"] {
    --background-color: #000;
    --text-color: #fff;
}
body {
    background-color: var(--background-color);
    color: var(--text-color);
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments