Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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