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. 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <h1>Packery demo - show spaces</h1>
<div class="packery">
  <div class="item w3"></div>
  <div class="item h4"></div>
  <div class="item w3"></div>
  <div class="item w2 h3"></div>

              * {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;

body { font-family: sans-serif; }

.packery {
  border: 1px solid;
  max-width: 520px;

/* clearfix */
.packery:after {
  content: ' ';
  display: block;
  clear: both;

.item {
  width: 40px;
  height: 40px;
  float: left;
  background: #C09;
  border: 4px solid #333;
  border-color: hsla(0, 0%, 0%, 0.3);
  opacity: 0.7;

.item:hover {
  border-color: white;
  cursor: move;

.item.w2 { width:   80px;  }
.item.h2 { height:  80px;  }
.item.w3 { width:  120px; }
.item.h3 { height:  120px; }
.item.h4 { height: 160px;  }
.item.w4 { width:  160px;  }

.item.is-positioning-post-drag {
  border-color: white;
  background: #09F;
  z-index: 2;

.packery canvas {
  position: absolute;

              // https://packery.metafizzy.co/packery.pkgd.js and 
// https://draggabilly.desandro.com/draggabilly.pkgd.js added as external resource

var container = document.querySelector('.packery');
var pckry = new Packery( container, {
  itemSelector: '.item',
  columnWidth: 40,
  rowHeight: 40
var itemElems = pckry.getItemElements();
// for each item element
for ( var i=0, len = itemElems.length; i < len; i++ ) {
  var elem = itemElems[i];
  // make element draggable with Draggabilly
  var draggie = new Draggabilly( elem );
  // bind Draggabilly events to Packery
  pckry.bindDraggabillyEvents( draggie );

// draw spaces on canvas
var canvas = container.querySelector('canvas');
var ctx = canvas.getContext('2d');

function drawSpaces() {
  // reset canvas size
  canvas.width = pckry.size.width;
  canvas.height = pckry.size.height;
  // all Packery's empty spaces
  var spaces = pckry.packer.spaces;
  ctx.fillStyle = 'hsla(150, 100%, 50%, 0.4)';
  ctx.strokeStyle = 'hsla(150, 100%, 30%, 0.8)';
  for ( var i=0, len = spaces.length; i<len; i++ ) {
    var space = spaces[i];
    // each space is a Rect object, just geometry
    // width, height, x, y
    var height = Math.min( space.height, canvas.height - space.y );
    // draw rectangle for space
    ctx.fillRect( space.x, space.y, space.width, height );
    ctx.strokeRect( space.x + 0.5, space.y + 0.5, space.width - 0.5, height - 0.5 );

pckry.on( 'layoutComplete', drawSpaces );
pckry.on( 'dragItemPositioned', drawSpaces );
//hack, trigger another layout for first rendering

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.