BentoGrid.js

A smart library that automatically positions elements depending on their size in a grid to create responsive and beautiful layouts.
Flexible
Easily set the size of elements via attributes
Smart
Automatic positioning of elements in the grid
Light­weight
Only 2KB (minified) with zero dependencies
Responsive
Adaptive grid layouts for various screen sizes

Installation

HTML

<script type="module">
	import BentoGrid from "https://cdn.jsdelivr.net/npm/@bentogrid/core@1.1.1/BentoGrid.min.js";
</script>

npm

npm i @bentogrid/core
import BentoGrid from "@bentogrid/core";

Basic Usage

<div class="bentogrid">
	<div data-bento="1x1"></div>
	<div data-bento="2x2"></div>
	<div data-bento="2x1"></div>
	<!-- Add elements or fillers -->
</div>
const myBento = new BentoGrid({
	// Add configuration options
});

Elements vs. Fillers

Elements

Fillers

Example 1: Unstyled Fillers

In this example fillers are automatically created, but they are not styled and therefore invisible.

#bentogrid > *[data-bento] {
  @apply bg-sand-200;
}

Example 2: Styled Fillers

In this example, fillers are automatically created and styled via CSS.

#bentogrid > * {
  @apply bg-sand-200;
}
#bentogrid .bento-filler {
  @apply bg-black;
}

Example 3: Individual Fillers (automatically looped)

In this example custom fillers are added to the grid. The fillers are automatically looped to fill the grid.
<div id='bentogrid'>
  <div data-bento='2x2'></div>
  ...
  <div class='bg-water-300'></div>
  <div class='bg-water-600'></div>
  <div class='bg-water-900'></div>
</div>

UserConfig

target

In this example the element with the ID `bentogrid-config-target` is targeted to initialize BentoGrid.

new BentoGrid({
  target: "#bentogrid-config-target",
  cellGap: 6,
  columns: 8,
  aspectRatio: 1,
});

As an alternative you can also pass the element directly to the `target` option.

new BentoGrid({
  target: document.getElementById("bentogrid-config-target-element"),
  cellGap: 6,
  columns: 8,
  aspectRatio: 1,
});

cellGap

In this example the cellGap is set to 24.

new BentoGrid({
  cellGap: 24,
  target: "#bentogrid-config-cell-gap",
  columns: 8,
  aspectRatio: 1,
});

aspectRatio

In this example the cellGap is set to 9 / 16, which means that a single cell in the grid has a ratio of 9 / 16. An element taking up 2 columns and 1 row will have a ratio of about 18 / 16.

new BentoGrid({
  aspectRatio: 9 / 16,
  cellGap: 6,
  target: "#bentogrid-config-aspect-ratio,
  columns: 8,
});

balanceFillers

new BentoGrid({
  balanceFillers: true,
  cellGap: 6,
  target: "#bentogrid-config-balance-fillers,
  aspectRatio: 1,
  columns: 8,
});

minCellWidth

new BentoGrid({
  minCellWidth: 50,
  balanceFillers: true,
  cellGap: 6,
  target: "#bentogrid-config-min-cell-width,
  aspectRatio: 1
});

columns

new BentoGrid({
  columns: 5,
  balanceFillers: true,
  cellGap: 6,
  target: "#bentogrid-config-columns,
  aspectRatio: 1,
});

breakpoints

breakpointReference

Breakpoint

cellGap

aspectRatio

minCellWidth

columns

Hint: Further documentation is coming soon.