---

title: Introduction
category: docs
layout: default
toc:
  - { title: Getting started, anchor: getting_started }
  - { title: Code repository, anchor: code_repository }
  - { title: Acknowledgments, anchor: acknowledgments }
  - { title: Changelog, anchor: changelog }
  - { title: License, anchor: license }

---

Masonry is a dynamic grid layout plugin for jQuery. Think of it as the flip-side of CSS floats. Whereas floating arranges elements horizontally then vertically, Masonry arranges elements vertically, positioning each element in the next open spot in the grid. The result minimizes vertical gaps between elements of varying height, just like a mason fitting stones in a wall.

## Getting started



### Markup

Masonry works on a container element with a group of similar child items.

{% highlight html %}

<div id="container">
  <div class="item">...</div>
  <div class="item">...</div>
  <div class="item">...</div>
  ...
</div>

{% endhighlight %}

Add jQuery and the Masonry script. Masonry requires jQuery v1.5 and greater.

{% highlight html %}

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="/path/to/jquery.masonry.min.js"></script>

{% endhighlight %}

### CSS

All sizing of items is handled by your CSS. Items should be floated.

{% highlight css %}

.item {
  width: 220px;
  margin: 10px;
  float: left;
}

{% endhighlight %}

### Script

It is recommended you specify an `itemSelector` and `columnWidth`. There are a number of other [options](options.html) you can specify.

{% highlight javascript %}

$(function(){
  $('#container').masonry({
    // options
    itemSelector : '.item',
    columnWidth : 240
  });
});

{% endhighlight %}

That's it!

[**See Demo: Basic multi-column**](../demos/basic-multi-column.html)


### imagesLoaded plugin

If your content contains any images, you'll want to ensure that Masonry is triggered after all the images your content has loaded. The included [imagesLoaded plugin](https://github.com/desandro/imagesloaded) makes this easy.

{% highlight javascript %}

var $container = $('#container');
$container.imagesLoaded(function(){
  $container.masonry({
    itemSelector : '.item',
    columnWidth : 240
  });
});

{% endhighlight %}

[See Demo: Images](../demos/images.html)

## Code repository

This project lives on GitHub at [github.com/desandro/masonry](http://github.com/desandro/masonry). There you can grab the latest code and follow development.

## Acknowledgments

+ Louis-Rémi Babé and Paul Irish for the [jQuery SmartResize plugin](http://github.com/louisremi/jquery-smartresize). De-bounced window resize event handler. Used within Masonry.
+ Paul Irish and Luke Shumard for [Infinite Scroll](http://www.infinite-scroll.com). Pretty much Masony's BFF &lt;3.
+ The Modernizr team for [Modernizr](http://www.modernizr.com/). Used in most of these demos.
+ Paul Irish et. al. for [imagesLoaded plugin](https://gist.github.com/268257). Used within Masonry.
+ [Ralph Holzmann](http://twitter.com/ralphholzmann) for re-writing the [jQuery Plugins/Authoring tutorial](http://docs.jquery.com/Plugins/Authoring) and opened my eyes to [Plugin Methods](http://docs.jquery.com/Plugins/Authoring#Plugin_Methods) pattern.
+ [Eric Hynds](http://www.erichynds.com/) for his article [Using $.widget.bridge Outside of the Widget Factory](http://www.erichynds.com/jquery/using-jquery-ui-widget-factory-bridge/) which provided the architecture for Masonry.

## Changelog

<dl>
  <dt>v2.1: 9 Dec 2011</dt>
    <dd>Pass in a function for <code>columnWidth</code> for easier fluid layouts</dd>
  <dt>v2.0: May 2011</dt>
    <dd>Complete re-write. Uses <code>$.Mason</code> constructor, like jQuery UI widget</dd>
    <dd>Add options <code>gutterWidth</code>, <code>isFitWidth</code> for centering layout, <code>isRTL</code> for right-to-left layout</dd>
    <dd>Add all new methods like <code>appended</code>, and <code>reload</code></dd>
    <dd>Remove filtering demos</dd>
  <dt>v1.3: 3 Sep 2010</dt>
    <dd>Revamped <code>appendedContent</code> to work with container elements.  Plays nice with latest Infinite Scroll.</dd>
    <dd>Revised layout for documentation to allow for more pages.</dd>
  <dt>v1.2: 12 Jun 2010</dt>
    <dd>Support for filtering added</dd>
  <dt>v1.1: 29 Apr 2010</dt>
    <dd>Add animation</dd>
  <dt>v1.0: 7 Dec 2009</dt>
    <dd>Multi-column width support</dd>
  <dd>Appending elements and Infinite Scroll support</dd>
    <dd>Less obstrusive layout. No inserting additional markup.</dd>
    <dd>Automatically binds event to window resizing</dd>
  <dt>v0.4: 14 Jun 2009</dt>
    <dd>Better fluid rearrangement support</dd>
  <dt>v0.1: Feb 2009</dt>
    <dd>Original release</dd>
</dl>

## License

jQuery Masonry is licensed under the MIT license. It may be used for personal and commercial applications.

<div class="license-copy">
  <h3>The MIT License</h3>
  <p>Copyright &copy; 2012 David DeSandro</p>
  <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
  <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
  <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</div>