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

+ 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

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

              
                <div class="wrapper">
  <div class="heightKepper"></div>
  <textarea class="textarea">This Textarea is autosizing
    
The neccessary height is stored in the textarea.scrollHeight.
But to get it, the height must be set  to inherit.
While setting the height of the element to inherit, some browsers set it to the 
realy small initial height and shortens the document body by that way.

The browser scrolls in a bad way.

To prevent that, the textarea gets wrapped in the flexbox with an second and invisible 
Element side by side. The Heightkepper does its job an sets the height of the flexbox.</textarea>
</div>
              
            
!

CSS

              
                .wrapper {
  display: flex;
  flex-direction: row;
  align-items: flex-sart;
}

.heightKepper {
  width: 1px;
  margin-right: -1px;
}

.textarea {
  overflow: hidden;
  flex-grow: 1; 
  resize: none;
}
              
            
!

JS

              
                const textarea = document.querySelector(".textarea")
const heightKeeper = document.querySelector(".heightKeeper")

function setHeight() {
  // The neccessary height is stored in the scrollHeight
  // but to get it, the height must be set  to inherit
  textarea.style.height = "inherit"  
  // update the height
  textarea.style.height = textarea.scrollHeight+"px"
  
  // While setting the height of the element to inherit, some browsers set it to the 
  // realy small initial height and shortens the document body by that way.
  // The browser scrolls in a bad way.
  // To prevent that, the textarea gets wrapped in the flexbox with an second and invisible 
  // Element side by side. The Heightkepper does its job an sets the height of the flexbox..
  heightKeeper.style.height = textarea.scrollHeight+"px"
}

textarea.addEventListener("input", setHeight)
window.addEventListener("resize", setHeight)
setHeight()
              
            
!
999px

Console