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="container">
  <div class="web-page">
    <div class="dynamic-content-wrapper" id="wrapper-1">
    </div>
    <h1>My Article</h1>
    <p>
      See, if you start reading this article you'll notice eventually that you lose your place, because an ad jumps in and shifts all the content from under your eyes.
    </p>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi eaque adipisci vitae vero debitis reprehenderit modi molestiae quasi sapiente porro rerum, quos qui culpa suscipit nam cumque nesciunt ex? Dolorem!
    </p>
  </div>
  <div class="web-page">
    <div class="dynamic-content-wrapper" id="wrapper-2">
    </div>
    <h1>My Article</h1>
    <h3>(Slides down if layout shifts!)</h3>
    <p>
      This article, on the other hand (clearly a much better article), will not. The space has already been reserved at the top, and it won't shove your article out of the way when the ad gets around to arriving.
    </p>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis veniam accusantium similique officia laborum excepturi quod, porro dignissimos sint doloribus magnam accusamus eius voluptate dolorum assumenda. Similique, sequi tenetur quod!
    </p>
  </div>
</div>
              
            
!

CSS

              
                /* Just for visuals; not relevant to what's being demonstrated */

body {
  background-color: #B2EBF2;
  font: 14px Sans-Serif;
}

.container {
  text-align: center;
  padding: 10px 5px;
}

.web-page {
  padding: 15px;
  display: inline-block;
  width: 25%;
  min-width: 180px;
  max-width: 300px;
  height: 300px;
  margin: 10px;
  border: 2px black solid;
  overflow-y: scroll;
  text-align: left;
  background-color: white;
}

.dynamic-content {
  height: 100px;
  width: 100%;
  background-color: #0D47A1;
  color: #eee;
  text-align: center;
  line-height: 100px;
  font-size: 16px;
  font-weight: bold;
}

#wrapper-2 {
  height: 0;
  overflow: hidden;
  transition: height 0.66s ease-out;
}
#wrapper-2.loaded {
  height: 100px;
}
              
            
!

JS

              
                /* Simulate an ajax-loaded ad with a delayed DOM insertion */
setTimeout(function() {
  $('#wrapper-1').html('<div class="dynamic-content">Ad 😠</div>');
}, 2000);

setTimeout(function() {
  var el = $('#wrapper-2');
  el.html('<div class="dynamic-content">Ad 😊</div>');
  onLoad(el);
}, 2000);

function onLoad(element) {
  $(element).addClass('loaded');
}
              
            
!
999px

Console