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

+ 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.


  <h2>Different Ways to get an Element's Dimensions with DOM Scripting</h2>
  <p>The box below has dimensions set in the CSS at 205.3px by 198.8px. Using JavaScript, you can get the width and height values, but the results may differ depending on what DOM method or property you use.</p>
  <p>The button below grabs the box's width and height in six different ways, each of which will be displayed on the page when the button is clicked.</p>

  <div class="box"></div>

  <button>Get Box Dimensions</button>


                body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px;

main {
  text-align: center;
  margin: 0 auto;
  max-width: 800px;

p {
  text-align: left;
  padding: 0 20px;

code {
  color: firebrick;

.box {
  width: 205.3px;
  height: 198.8px;
  border: solid 2px #ccc;
  margin: 20px auto;
  box-sizing: border-box;
  background: lemonchiffon;

output {
  display: block;
  text-align: center;
  padding: 20px;
  line-height: 1.5;


                let box = document.querySelector('.box'),
  btn = document.querySelector('button'),
  op = document.querySelector('output');

btn.addEventListener('click', function() {
    op.innerHTML = `
      Using <code>getBoundingClientRect()</code>: ${box.getBoundingClientRect().width} x 
      Using <code>offsetWidth/offsetHeight</code>: ${box.offsetWidth} x 
      Using <code>window.getComputedStyle()</code>: ${window.getComputedStyle(box).width} x 
      Using <code>document.styleSheets</code>: ${document.styleSheets[1].cssRules[4].style.width} x 
      Using <code>scrollWidth/scrollHeight</code>: ${box.scrollWidth} x 
      Using <code>clientWidth/clientHeight</code>: ${box.clientWidth} x