This repo provides a simple example of a themes implmented using pure vanilla HTML, JS and CSS. It demonstrates how to create themes and a theme switches that respects the user's system preference and saves their choice for future visits.
The example showcases:
- 🔎 Automatic theme detection: Automatically applies the system's preferred color scheme. (light or dark mode)
- ⚙️ Theme toggle: Allows users to manually switch between light and dark themes.
- 💾 Persistent user preference: Saves the user's theme choice using local storage, so their preference is preserved across page reloads.
- 👀 Listens to the theme system: If the system theme changes, the theme will be automatically changed on the website.
index.html: Basic HTML structure with a theme toggle button.style.css: Example CSS with styling for LIGHT and DARK modes.script.js: JavaScript to handle theme switching, system theme and persistent storage.
- Clone the repository
git clone https://github.com/Moderrek/vanilla-theme
- Enter the project directory
cd vanilla-theme - Open
index.htmlin your browser - Explore files and learn.
Feel free to fork the repository and modify the example as needed for your own projects. If you have any improvements or suggestions, please submit a pull request.
MIT License
Copyright (c) 2024 Tymon Woźniak
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


