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="big">
  <div class="corner top-right">top right</div>
  <div class="corner bottom-right">bottom right</div>
  <div class="corner bottom-left">bottom left</div>
  <div class="corner top-left">top left</div>

<pre class="info">
getComputedStyle()
  width: <span id="computed-width"></span>
  height: <span id="computed-height"></span>

getBoundingRect()
  width: <span id="rect-width"></span>
  height: <span id="rect-height"></span>
</pre>
</div>

              
            
!

CSS

              
                body {
  margin: 0;
  font: 1.25rem/1.25 'Noto Sans Mono', monospace;
}

.big {
  position: relative;
  width: calc(infinity * 1px);
  height: calc(infinity * 1px);
  background: linear-gradient(135deg,
    #f8f9fa 25%,
    #f1f3f5 25%,
    #f1f3f5 50%,
    #f8f9fa 50%,
    #f8f9fa 75%,
    #f1f3f5 75%,
    #f1f3f5 100%
  );
  background-size: 40px 40px;
}

.corner {
  position: absolute;
  padding: 5px;
  color: #fff;
  background-color: #5c940d;
}

.top-right {
  top: 0;
  right: 0;
}

.bottom-right {
  bottom: 0;
  right: 0;
}

.bottom-left {
  bottom: 0;
  left: 0;
}

.top-left {
  top: 0;
  left: 0;
}

.info {
  display: inline-block;
  margin: 50px;
  padding: 20px;
  color: #fff;
  background-color: #000c;
}

              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {
  const bigEl = document.querySelector('.big');
  
  // getComputedStyle()
  const computed = window.getComputedStyle(bigEl);
  const computedWidth = computed.getPropertyValue('width');
  const computedHeight = computed.getPropertyValue('height');

  // getBoundingRect()
  const rect = bigEl.getBoundingClientRect();
  const rectWidth = rect.width + 'px';
  const rectHeight = rect.height + 'px';

  // output
  document.getElementById('computed-width').innerText = computedWidth;
  document.getElementById('computed-height').innerText = computedHeight;
  document.getElementById('rect-width').innerText = rectWidth;
  document.getElementById('rect-height').innerText = rectHeight;
});

              
            
!
999px

Console