FAQ

How do I fix overlapping item elements?

If your layout has images, you probably need to use imagesLoaded.

Overlaping items are caused by items that change size after a layout. This is caused by unloaded media: images, web fonts, embedded buttons. To fix it, you need to initialize or layout after all the items have their proper size.

What is the difference between Masonry, Isotope, and Packery?

Masonry, Isotope, and Packery are all similar in that they are layout libraries. Many of their options and methods are the same.

Masonry does cascading grid "masonry" layouts. Packery does bin-packing layouts, which allow it to be used for draggable interactions.

Isotope does sorting and filtering. Isotope uses masonry layouts, as well as other layouts.

Masonry is licensed MIT and is freely available for use and distribution. Isotope and Packery have a proprietary license, where you can purchase a license for commercial projects, or use it freely for open-source projects.

The first item breaks the grid!

You most likely need to set the columnWidth option. Without columnWidth set, Masonry will use the width of the first item for the size of its columns.

// jQuery
$('.grid').masonry({
  columnWidth: 200
});
// vanilla JS
var msnry = new Masonry( '.grid', {
  columnWidth: 200
});

Error: “cannot call methods on masonry prior to initialization; attempted to call '___'”

This error occurs when your code attempts to use a method before the Masonry instance has been initialized.

// This code will trigger the "cannot call methods" error

$grid.append( $items )
  // masonry method
  .masonry( 'appended', $items );

// init Masonry
$grid.masonry({
  // options...
});

This can happen if you have a race condition — when one piece of logic may occur before another. This could happen with imagesLoaded, Infinite Scroll, or Ajaxing content.

// race condition with imagesLoaded

$grid.imagesLoaded( function() {
  // init Masonry
  $grid.masonry({
    // options...
  });
});

// imagesLoaded will trigger after this
$grid.append( $items )
  .masonry( 'appended', $items );

To resolve this, make sure that the Masonry instance has been initialized before the method is called.

$grid.imagesLoaded( function() {
  // init Masonry
  $grid.masonry({
    // options...
  });
  // Masonry has been initialized, okay to call methods
  $grid.append( $items )
    .masonry( 'appended', $items );
});
// another fix, init Masonry first, before imagesLoaded
$grid.masonry({
  // options...
});
// okay to call methods
$grid.append( $items )
  .masonry( 'appended', $items );
// just do layout on imagesLoaded
$grid.imagesLoaded( function() {
  $grid.masonry('layout');
});