Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@jmwhittaker /app.js
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Standard compliant stylesheet switcher for HTML5. Works on iOS5 and all modern browsers.
/* Check to see if we have saved a style already, a bit verbose but you get the drift! */
var theme = localStorage.getItem('style');
if (!theme) {
localStorage.setItem('style', 'light');
theme = localStorage.getItem('style');
if (theme === 'light') {
theme = 'dark';
} else {
theme = 'light';
localStorage.setItem('style', theme);
return false;
function updateTheme()
currentTheme = localStorage.getItem('style');
$('meta[http-equiv=Default-Style]')[0].content = currentTheme;
<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<meta http-equiv="Default-Style" content="">
<title>Stylesheet Switcher</title>
<!-- CSS -->
<link rel="stylesheet" href="/styles/darktheme.css" title="dark">
<link rel="stylesheet" href="/styles/lighttheme.css" title="light">
<script src="//"></script>
<script src="app.js"></script>
<h1>Hello World</h1>
<a href="#" class="js-change-style">change style</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.