Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

HTML

              
                
              
            
!

CSS

              
                div {
  width: 150px;
  height: 150px;
  display: inline-block;
  text-align: center;
  line-height: 150px;
}
div p {
  margin: 0px;
  font-size: 2em;
}
              
            
!

JS

              
                function invertColor(hex) {
    //      /-- add the # to the front of the code
    //      |   /-- #ffffff converted to a decimal
    //      |   |                       /-- strip out any # in the input
    //      |   |                       |                   /-- cast the string to an int assuming the string is base16
    //      |   |                       |                   |    /-- convert inverse decimal to base 16 string
    //      |   |                       |                   |    |            /-- pad the front with 0s if the decimal number is small
    //      |   |                       |                   |    |            |
    return '#'+(16777215 - parseInt(hex.replace(/\#/g, ''), 16)).toString(16).padStart(6, '0');
}



// Let's generate a bunch of boxes with random colors and labels that are the inverse of those colors
(function() {
  for (var i = 0; i < 50; i++) {
    color = '#'+(Math.random()*0xFFFFFF<<0).toString(16); // generate random color
    var div = document.createElement('div'); // create div element
    div.style.backgroundColor = color; // set background-color on that div to the color we generated
    var label = document.createElement('p'); // create a p element
    label.textContent = color; // set the text of the p element to the color
    label.style.color = invertColor(color); // set the color of the p element to the inverseColor
    div.appendChild(label); // put the p inside the div
    document.body.appendChild(div); // add the div to the body
  }
}())
              
            
!
999px

Console