Dynamic Grid Layout Generator – Magic Grid

Category: Javascript , Layout , Recommended | November 21, 2018
Author: e-oj
Views Total: 240
Official Page: Go to website
Last Update: November 21, 2018
License: MIT


Dynamic Grid Layout Generator – Magic Grid


Magic Grid is a lightweight (3kb minified) JavaScript library to generate a dynamic, flexible grid layout using pure JavaScript.

How to use it:

Install & download.

$ npm install magic-grid --save

Load the minified version of the Magic Grid library in the html document.

<script src="/dist/magic-grid.umd.js"></script>

Create a container to place the grid layout.

<div class="container">

Create a dynamic grid layout and specify the number of grid items to generate.

let magicGrid = new MagicGrid({
    container: "#container",
    items: 20


Create a static grid layout from existing grid items.

<div class="container">
  <div class="item1">1</div>
  <div class="item2">2</div>
  <div class="item3">3</div>
  <div class="item4">4</div>
  <div class="item5">5</div>
  <div class="item6">6</div>
  <div class="item7">7</div>
  <div class="item8">8</div>
  <div class="item9">9</div>
  <div class="item10">10</div>
let magicGrid = new MagicGrid({
    static: true


Set the space between grid items. Default: 25px.

let magicGrid = new MagicGrid({
    gutter: 30

Set the maximum number of grid items.

let magicGrid = new MagicGrid({
    maxColumns: 100

Decide whether to append next element to the shortest column.

let magicGrid = new MagicGrid({
    useMin: false

Enable/disable the animation when changing screen size.

let magicGrid = new MagicGrid({
    animate: false

Trigger a repositioning function after new grid items added to the grid layout.



v3.0.8 (11/21/2018)

  • modified ready check


  • no top gutter on first row


  • stretch container to grid height


  • Refactor

You Might Be Interested In:

Leave a Reply