A small, lightweight JavaScript plugin for placing items in straight rows (jQuery and vanilla JS version) – Demo:
HTML JavaScript
Latest commit bb9cc06 Sep 9, 2017 @brunjo release 1.0.6
Failed to load latest commit information.
example fix #24 May 6, 2016
LICENSE Initial commit Feb 9, 2014
README.md add bower and npm install instructions Feb 2, 2016
bower.json release 1.0.6 Sep 9, 2017
jquery.row-grid.js define $this variable Sep 5, 2017
jquery.row-grid.min.js release 1.0.6 Sep 9, 2017
package.json release 1.0.6 Sep 9, 2017



rowGrid.js is a small, lightweight (~900 bytes gzipped) jQuery plugin for placing images (or other items) in straight rows.

The grid is similar to grids on Google Image Search, flickr, shutterstock and Google+ images.


  • responsive
  • infinite scrolling
  • support for all modern browsers and IE >= 8

A vanilla JavaScript version is available that doesn't require jQuery: https://github.com/brunjo/rowGrid

Example Grid

Do you like this project? Follow me on Twitter @3runjo.

How does it work?

All items must have the same height but the width can be variable. RowGrid.js justifies the items in straight rows so that the width of the rows equals the width of the container/parent element. At first rowGrid.js adjusts the margin between the items. If this is not enough rowGrid.js scales down the items.

Demos & Examples

Examples with explanation: http://brunjo.github.io/rowGrid.js/

Real world example: http://www.pexels.com/


RowGrid.js requires jQuery 1.7 or above.

<script src="path/to/jquery.min.js"></script>
<script src="path/to/jquery.row-grid.min.js"></script>

You can install it also with Bower or npm:

  • Install with Bower: bower install rowGrid.js.
  • Install with npm: npm install rowgrid.js.


It is important that you either declare the width and height as attributes on the img tag or that you wait until the images are loaded before you start rowGrid.js.


<div class="container">
  <div class="item">
    <img src="path/to/image" width="320" height="200" />
  <div class="item">
    <img src="path/to/image" width="290" height="200" />


var options = {minMargin: 10, maxMargin: 35, itemSelector: ".item"};

Endless Scrolling


// append new items
$(".container").append("<div class='item'><img src='http://placehold.it/310x200' /></div>");
// arrange appended items


    itemSelector: ".item"
    minMargin: 10,
    maxMargin: 35,
    resize: true,
    lastRowClass: "last-row",
    firstItemClass: "first-item"

itemSelector (required)

  • value: string (CSS Selector)

You have to set this option. The selector have to reference to all grid items.


  • value: number or null
  • default value: null

This is the minimal horizontal margin between the items. The margin is only between the items not between the first/last item and the container.


  • value: number or null
  • default value: null

This is the maximal horizontal margin between the items.


  • value: boolean
  • default value: true

If resize is set to true the layout updates on resize events. This is useful for responsive websites.


  • value: string
  • default value: last-row

The first item in the last row gets this class.


  • value: string or null
  • default value: null

The first item in every row gets this class.