Pen Settings



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


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.


                <h1>Masonry + imagesLoaded, iteratively reveal items</h1>
<div id="container"></div>
<p><button id="load-images">Load images</button></p>



                body { font-family: sans-serif; }

#container {
  background: #DDD;
  max-width: 1000px;

.item {
  width: 200px;
  float: left;

.item img {
  display: block;
  width: 100%;

button { font-size: 18px; } 


                $( function() {

  var $container = $('#container').masonry({
    itemSelector: '.item',
    columnWidth: 200

  $('#load-images').click( function() {
    var $items = getItems();
    $container.masonryImagesReveal( $items );

$.fn.masonryImagesReveal = function( $items ) {
  var msnry ='masonry');
  var itemSelector = msnry.options.itemSelector;
  // hide by default
  // append to container
  this.append( $items );
  $items.imagesLoaded().progress( function( imgLoad, image ) {
    // get item
    // image is imagesLoaded class, not <img>, <img> is image.img
    var $item = $( image.img ).parents( itemSelector );
    // un-hide item
    // masonry does its thing
    msnry.appended( $item );
  return this;

function randomInt( min, max ) {
  return Math.floor( Math.random() * max + min );

function getItem() {
  var width = randomInt( 150, 400 );
  var height = randomInt( 150, 250 );
  var item = '<div class="item">'+
    '<img src="' + 
      width + '/' + height + '/nature" /></div>';
  return item;

function getItems() {
  var items = '';
  for ( var i=0; i < 12; i++ ) {
    items += getItem();
  // return jQuery object
  return $( items );