Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


    <h1>Background based on time of day</h1>
    <h4>JavaScript applies a CSS class to change the background image based on the time of day of the user's browser.</h4>


                body {
 margin: 0 50px;
 font-family: sans-serif

h1, h4 {
 margin: 0;

/* basic styles */
h1 {
 margin: 0 0 10px;

div {
 background: #0098d4;
 border-radius: 10px;
 color: #efefef;
 margin: 50px auto;
 padding: 25px;
 width: 600px;

/* backgrounds */
.day {
 background-color: yellow;

.sunset {
 background-color: silver;

.night {
 background-color: #2b2b2b;

/* Only necessary for demonstration */

 .night:after {
  color: red;
  content: "";
  font-size: 2em;
  position: absolute;
  bottom: 1em;
  left: 50%;
  transform: translate(-50%, -50%);
 .day:after {
  content: "It's DAY  :D";
 .sunset:after {
  content: "It's SUNSET  :)";
 .night:after {
  content: "It's NIGHT  :(";


                // needs jquery.min.js
	var d = new Date();
	var n = d.getHours();
	if (n > 19 || n < 6)
 		// If time is after 7PM or before 6AM, apply night theme to ‘body’
 		document.body.className = "night";
	else if (n > 16 && n < 19)
 		// If time is between 4PM – 7PM sunset theme to ‘body’
 		document.body.className = "sunset";
 		// Else use ‘day’ theme
 		document.body.className = "day";