I actually got inspiration from MacStories for mine. It’s pretty simple the way I did it. It’s CSS styling found here:
And to do the triggering/saving of your preference I used javascript. At the initial, it will check for the cookie and set the theme accordingly:
And then I added the icon that does the toggle, which is activated via javascript as well:
That’s it. It looks a lot more complicated than it really is.