The checkbox is styled using the :before and :after pseodo-classes. You can also use the :checked pseudoclass to add additional styles to the checkbox.
The js pretty minimal. Essentially, I toggle a class (in this case ‘nightmode’) whenever the checkbox is clicked. When the class of nightmode is added, the css updates.