[!NOTE] Check out solidtime - The modern Open Source Time-Tracker at solidtime.io
A "micro-framework" (*hacky script) that adds dark mode to any website with a single line of code.
You can learn more about how it works and how I made it here.
This project is still in a prototyping stage, and the API is still subject to change. Please only use it with a fixed minor version.
box-shadow
.Integration can be achieved by one of the following methods.
Add these lines to your HTML file:
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@bufferhead/nightowl@0.0.14/dist/nightowl.js"
></script>
To use nightowl with a bundler like Vite first install it with this command:
npm install @bufferhead/nightowl
Then add these lines to your HTML file:
<script type="module">
import { createNightowl } from '@bufferhead/nightowl'
createNightowl({
defaultMode: 'dark',
toggleButtonMode: 'newState'
})
</script>
'light' | 'dark'
'light'
Sets the default mode for users that have not set a preference yet and do not have a system preference for dark mode.
'currentState' | 'newState'
'currentState'
Configures what state of the toggle button should be shown to the user.
currentState
- Shows the state that is currently applied to the website.newState
- Shows the state that will be applied when the user clicks the button.You can exclude elements from being inverted in dark mode using the .nightowl-daylight
CSS class. Just add it to an element and it will show the element in the same way as the light mode.
<div>
<p>I'm inverted in Dark Mode</p>
<p class="nightowl-daylight">I'm not inverted in Dark Mode</p>
</div>
Please open an issue and wait for one of the Maintainers to approve it until you open a merge request.
This project is heavily inspired by Aral Balkan who wrote down this idea to implement dark mode in a few lines of CSS using CSS Filters.