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


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>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;  }, {
  border-color: white;
  background: #09F;
  z-index: 2;

.packery canvas {
  position: absolute;



                // and 
// 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