Skip to content

Instantly share code, notes, and snippets.

@archfizz
Created August 16, 2013 10:58
Show Gist options
  • Save archfizz/6248994 to your computer and use it in GitHub Desktop.
Save archfizz/6248994 to your computer and use it in GitHub Desktop.
Changes the background of a webpage to a random hex color and displays that hex value on the page.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Random Background Color</title>
<style>
h1 { color: white; text-align: center; font-family: sans-serif; }
</style>
</head>
<body>
<h1 id="c">#ffffff</h1>
<script>
var c = '#' + Math.floor(Math.random() * 16777215).toString(16);
document.body.style.background = c;
document.getElementById('c').innerHTML = c;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment