Skip to content

Getting Started

Masonry Grid is a fast, lightweight, and responsive masonry grid layout library. This guide will help you get started with Masonry Grid in your project.

  1. Install package by running the following command in your terminal:

    pnpm add @masonry-grid/vanilla

    or use a CDN:

    import { BalancedMasonryGrid } from 'https://cdn.skypack.dev/@masonry-grid/vanilla'
  2. Now you can import constructor and start using it in your project:

    <div class="masonry">
    <!-- Each item must have aspect-ratio set by --width and --height CSS variables -->
    <div class="frame" style="--width: 4; --height: 3;">
    <img src="https://picsum.photos/400/300" />
    </div>
    <div class="frame" style="--width: 1; --height: 1;">
    <img src="https://picsum.photos/200/200" />
    </div>
    <div class="frame" style="--width: 3; --height: 4;">
    <img src="https://picsum.photos/300/400" />
    </div>
    <div class="frame" style="--width: 3; --height: 4;">
    <img src="https://picsum.photos/300/400" />
    </div>
    <div class="frame" style="--width: 1; --height: 1;">
    <img src="https://picsum.photos/200/200" />
    </div>
    <div class="frame" style="--width: 4; --height: 3;">
    <img src="https://picsum.photos/400/300" />
    </div>
    </div>
  3. Run your application and see the masonry grid in action!