Balanced Layout Examples

Interactive demonstrations

New to Balanced Layout?

Get up and running in 5 minutes with our Quick Start Guide!

View Quick Start Guide Download RSL Example Pack

Balanced Layout (Masonry Style)

The balanced layout mode creates a masonry-style layout by distributing items into columns based on their height. Items are placed in the shortest column to create a balanced, visually appealing layout.

Key Features:
• Automatic height balancing across columns
• Responsive breakpoints via data-slots-* and/or data-cols-* (-xs, -sm, -md, -lg, -xl, -xxl) with inheritance
• Smooth transitions on resize
• Works with any content (cards, images, text blocks)
• Maintains existing RSL functionality for non-balanced layouts

Basic Balanced Layout

This layout uses data-layout="balanced" with: 1 column on phones, 2 columns on medium screens, and 3 columns from large screens and up, based on the configured data-slots-* values.

Card 1

This is a short card with minimal content.

Card 2

This is a tall card with more content to demonstrate the balancing algorithm.

The balanced layout will place items in the shortest column, creating a masonry effect.

This helps prevent large gaps at the bottom of columns.

Card 3

This is a medium-height card.

It has a bit more content than the short card.

Card 4

Another short card.

Card 5

Medium card here.

With some additional text content.

Card 6

A tall card with lots of content.

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

The balancing algorithm ensures this card is placed optimally.

Card 7

Short card example.

Card 8

Medium-height content here.

The layout adapts responsively.

Code • HTML

Card 1

Content here...

Card 2

More content...

How It Works

Setup

  1. Add CSS: Include styles/sections.css
  2. Add JavaScript: Include javascript/smart-sections-balanced.js
  3. Mark Container: Add data-layout="balanced" to your .responsive-slot-layout
  4. Set Columns: Use either:
    • data-slots-xs, data-slots-sm, data-slots-md, data-slots-lg, data-slots-xl, data-slots-xxl
    • or the equivalent data-cols-* attributes (data-cols-xs, data-cols-sm, etc.)
    You only need to define the breakpoints you care about; larger breakpoints inherit from the last defined value.

How the Algorithm Works

The balanced layout script:

  1. Reads the column count from data-slots-* and/or data-cols-* based on the container width
  2. Creates that many .rsl-smart-column wrapper divs
  3. Tracks the height of each column
  4. Places each .slot-item into the currently shortest column
  5. Recalculates on window resize with debouncing for performance

Breakpoints

Balanced layouts use the same breakpoint logic as the main RSL layout script: each larger breakpoint inherits from the last defined value.

  • XS (< 576px): uses data-slots-xs / data-cols-xs (default 1)
  • SM (≥ 576px and < 768px): uses data-slots-sm / data-cols-sm, falling back to XS if not set
  • MD (≥ 768px and < 992px): uses data-slots-md / data-cols-md, falling back to SM → XS
  • LG (≥ 992px and < 1200px): uses data-slots-lg / data-cols-lg, falling back to MD → SM → XS
  • XL (≥ 1200px and < 1600px): uses data-slots-xl / data-cols-xl, falling back to LG → … → XS
  • XXL (≥ 1600px): uses data-slots-xxl / data-cols-xxl, falling back to XL → … → XS

Comparison: Normal Grid vs Balanced Layout

Normal Grid Layout (CSS Grid)

The standard grid creates uniform columns, which can leave gaps when items have different heights.

Card A

Short content

Card B

Tall content with multiple paragraphs.

This creates gaps in the grid layout.

The balanced layout handles this better.

Card C

Medium content.

Card D

Short again

Balanced Layout (Masonry Style)

The balanced layout distributes items by height, minimizing gaps and creating a more compact layout.

Card A

Short content

Card B

Tall content with multiple paragraphs.

This creates gaps in the grid layout.

The balanced layout handles this better.

Card C

Medium content.

Card D

Short again

Required Files

Include in <head> • HTML



                        
Include before </body> • HTML