A super small library for applying custom CSS styles at night.


The easiest way to install is by using Bower

$ bower install goodnight

…or you could download it and refer to it in your HTML like so:

<script src="/path/to/goodnight.min.js"></script>

Remember to put and use Goodnight in the head of your document to avoid a flash of unstyled content for the night version.


The following is the most basic example of using Goodnight with JavaScript:


If you wanted to add more than one stylesheets, just use the css() method on each one.


This makes Goodnight search for dark.css in the styles directory and apply that from 6PM to 6AM. To set your own Goodnight times, use the AM and PM properties:

Goodnight.AM = 5; // 5AM
Goodnight.PM = 20; // 8PM

You can easily toggle light and dark styles using the toggle() method:

document.querySelector('#some-button').addEventListener('click', function () {
	Goodnight.toggle(); // This removes styles from document.head
}, false);

Lastly, you can append a class to the body when it is nighttime like this:


Adding multiple classes is possible as long as you seperate them using spaces.

Goodnight.class('my-first-night-class my-second-night-class');

Leaving out a class name will make it default to "goodnight".


Licensed under MIT. Created by Jared Cubilla.