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

              
                # Auto Resize a `<textarea>` with an `autosize` Attribute

First, a regular `<textarea>`.

<textarea>Will NOT auto resize.</textarea>

Now add an attribute to tell the element to automatically resize on input, i.e. `<textarea autosize>`.

<textarea autosize>Will auto resize.</textarea>

What about `<textarea>`s that get injected into the DOM after page load with the `autosize` attribute? A mutation observer can pick up on those and attach the appropriate events. This ensures any `<textarea autosize>` added to the DOM via JavaScript will resize as expected.

All other attributes on the `<textarea>` continue to work as normal.
              
            
!

CSS

              
                textarea {
  display: block;
  margin: 20px 0;
  width: 400px;
}
              
            
!

JS

              
                import autosize from "https://unpkg.com/autosize@4.0.2/src/autosize.js";

// Autosize anything in the DOM on page load
document.querySelectorAll("textarea[autosize]")
  .forEach(autosize);

// Setup observer to autosize anything after page load
new MutationObserver(mutations => {
  Array.from(mutations).forEach(mutation => {
    Array.from(mutation.addedNodes).forEach(node => {
      if (node.matches("textarea[autosize]")) {
        autosize(node);
      }
    });
  });
}).observe(document.body, { childList: true });

// Simulate injecting new <textarea> nodes
setTimeout(() => {
  const t1 = document.createElement("textarea");
  t1.setAttribute("autosize", true);
  t1.innerHTML = "Injected after page load. Will auto resize."
  document.body.appendChild(t1);
  
  const t2 = document.createElement("textarea");
  t2.innerHTML = "Injected after page load. Will NOT auto resize."
  document.body.appendChild(t2);
}, 1000)
              
            
!
999px

Console