Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

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

Packages

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.

Behavior

Auto Save

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.

HTML

              
                <div class="element"></div>
<div class="element"></div>
<button>Switch</button>
<div class="feedback">
  <h5>onClick Data:</h5>
  <hr>
  <p class="output"></p>
</div>

              
            
!

CSS

              
                body {
  padding: 1.425em;
  background: #badbad;
  font-size: 16px;
}
.element {
  display: inline-block;
  margin: 0.25em;
  height: 40px;
  width: 120px;
  background: rgb(35, 163, 211);
  border: 2px solid #71cda0;
  box-shadow: inset 0 1px 1px 0 rgba(105, 105, 105, 0.4),
              1px 2px 0 #2d851d,
              -1px 2px 0 #2d851d;
}
.element:nth-child(2n+1) {
  position: relative;
  background: rgb(255, 99, 71);
}
button {
  display: block;
  margin: 0.25em 0 0 98px;
  padding: 0.325em;
  background: transparent;
  color: #156341;
  text-shadow: 0 1px 0 rgba(#ada, 0.8);
  border: 1px solid #156341;
  border-radius: 3px;
  box-shadow: 0 0 2px rgba(21, 99, 65, 0.7)
}
.feedback {
  margin-top: 0.625em;
  padding: 0 0.425em;
  border-radius: 3px;
  border: 1px dotted rgba(21, 99, 65, 0.3);
  max-width: 22.3em;
  background: #c4daaf;
  color: darken(rgb(21, 99, 65), 10);
  opacity: 0.8;
}
.feedback > h5 {
  margin: 0.4em;
}
.feedback > hr {
  opacity: 0.2;
}
.feedback > .output {
  max-height: 23.2em;
  width: 30em;
  overflow: auto;
  font-size: 0.75em;
}
              
            
!

JS

              
                // Change group of elements' bg color between 2 colors
function changeColor(el, color1, color2) {
  
  // Loop through elements
  for (var x = 0; x < el.length; x++) {
    // Output element's bg color before change
    output('Before:');
  	output('    > ' + "$('element')[" + x + '].backgroundColor: ' + getComputedStyle(el[x], null).backgroundColor);
    // Element bg color matches first color param
    if (getComputedStyle(el[x], null).backgroundColor === color1) {
      // Change bg color to second color param
      el[x].style.backgroundColor = color2;
    // Element bg color does NOT match first color param
    } else {
      // Change color to first color param
      el[x].style.backgroundColor = color1;
    }
    // Output element's bg color after change
    output('After:');
  	output('    > ' + "$('element')[" + x + '].backgroundColor: ' + getComputedStyle(el[x], null).backgroundColor + '<br>');

  }
}

// Output data text to the screen
function output(str) {
  el = $('.feedback > .output');
  txt = el.html();
	el.html(txt + str + '<br>');
  // scroll to bottom to display latest results
  el[0].scrollTop = el[0].scrollHeight;
}

// Handler for button click
$('button').on('click', function(e) {
  // We don't want the button to do anything other than what we tell it to
  e.preventDefault();
  // Change elements' bg color
  // rgb(35, 163, 211) = blue
  // rgb(255, 99, 71) = orange
  changeColor($('.element'), 'rgb(35, 163, 211)', 'rgb(255, 99, 71)');
});

              
            
!
999px

Console