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

              
                <span class="button" id="toggle_rounded">Toggle rounded</span>
<span class="button" id="change_size">Change size</span>

<div id="box"></div>


              
            
!

CSS

              
                /*
This example shows how to use JavaScript to: 1. Toggle a transition by adding/removing a class (rounded corners)
2. Use a transition to smooth out dynamic changes from JavaScript (changing size)
*/

/* This is box that will get the transitions */
#box {
  width: 150px;
  height: 150px;
  background: red;
  margin-top: 20px;
  margin-left: auto;
  margin-right: auto;
  
  /* We specify transitions for the border-radius and width/height. Multiple transitions are separated by commas */
  transition: border-radius 1s, width 1s ease-in-out, height 1s ease-in-out;
}

.button {
  background: green;
  padding: 5px;
}

/* We'll add/remove this class from JS to make the box rounded */
.rounded {
  border-radius: 25%;
  transition: border-radius 1s;
}


              
            
!

JS

              
                let rounded_button = document.getElementById('toggle_rounded');
let box = document.getElementById('box');

rounded_button.addEventListener('click', function() {  
  console.log('toggle_rounded');
  // Add/remove the "rounded" class
  box.classList.toggle('rounded');
});

let size_button = document.getElementById("change_size");
size_button.addEventListener('click', () => {
  console.log("change_color");
  
  let newSize = Math.round(Math.random() * 100);
  box.style.width = newSize + 'px';
  box.style.height = newSize + 'px';
});
              
            
!
999px

Console