Pen Settings



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


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.


                <p class="toggle">Toggle size <input type="checkbox" class="js-toggle"></p>

<div class="sizes">
  <p>Text width: <span class="js-text-width">0px</span></p>
  <p>Text height: <span class="js-text-height">0px</span></p>
  <p>Image width: <span class="js-image-width">0px</span></p>
  <p>Image height: <span class="js-image-height">0px</span></p>

<div class="container is-small">
  <div class="box content-box">
    <h2>Resize Observer</h2>
    <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Rem impedit necessitatibus dolore dolorem voluptates et quo illum, nihil officia perferendis illo quisquam totam? Reiciendis nisi voluptatibus velit numquam doloribus sit.</p>
  <img src="" alt="">


                .container {
  max-width: 800px;
  transition: max-width 2s;
  &.is-small {
    max-width: 250px;

.box {
  max-width: 600px;
  border: 2px solid #000;
  padding: 10px;
  p {
    max-width: 350px;
  img {
    display: block;
    max-width: 550px;
    width: 100%;
    height: auto;

.toggle {
  margin: 0 0 20px;

.sizes {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 200px;
  background: orange;
  padding: 10px 15px;
  z-index: 10;


                const c = u('.container');

u('.js-toggle').on('click', () => {
  if (c.hasClass('is-small')) {
  } else {

const tWidth = document.querySelector('.js-text-width');
const tHeight = document.querySelector('.js-text-height');
const iWidth = document.querySelector('.js-image-width');
const iHeight = document.querySelector('.js-image-height');

const ro = new ResizeObserver((entries, observer) => {
   for (let entry of entries) {
     const { target } = entry;
     const width = entry.contentRect.width.toFixed(2);
     const height = entry.contentRect.height.toFixed(2);
     if (target.tagName === 'IMG') {
       iWidth.textContent = `${width}px`;
       iHeight.textContent = `${height}px`;
     } else if (target.tagName === 'P') {
       tWidth.textContent = `${width}px`;
       tHeight.textContent = `${height}px`;

ro.observe(document.querySelector('.box p'));
ro.observe(document.querySelector('.box img'));