Adaptive Density Mode

Interactive examples and demonstrations

What is Adaptive Density?

Adaptive Density Mode automatically adjusts spacing, gaps, and padding throughout your layout based on the user's input device. Touch users get more spacious layouts, while mouse users get more compact layouts.

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

View Quick Start Guide
Features
• Automatic pointer type detection (touch vs mouse)
• Three density levels: compact, standard, spacious
• Manual override via data attributes
• Integrates with balanced layout & sidebar
• Respects accessibility preferences
• CSS variable-based for easy customization
• Works with all RSL layout modes

Browser Support
• All modern browsers (Chrome, Firefox, Safari, Edge)

Auto-Detection Demo

This layout automatically detects your pointer type. Try viewing this page on different devices!

Current Pointer: Detecting...
Auto Density: Detecting...
Slot 1
Slot 2
Slot 3
Code • HTML



Content 1
Content 2
Content 3

Manual Density Override

Use data-rsl-density to manually set the density level.

Current Density: standard
1
2
3
4
5
6
7
8
Code • HTML


...
...
...

Density with Balanced Layout

Density mode works seamlessly with the balanced (masonry) layout system.

Item 1
Item 2 (tall)
Item 3
Item 4
Item 5
Item 6
Code • HTML

Content 1
Content 2
Content 3

Density with Sidebar Layout

Sidebar margins adapt to the current density level.

Code • HTML

Main content

Programmatic API

Control density via JavaScript using the RSL.Density API.

Click button to run API demo...
Code • JavaScript

// Get element
const layout = document.querySelector('.slot-layout');

// Set density manually
RSL.Density.set(layout, 'spacious');

// Get current density
const current = RSL.Density.get(layout);
console.log(current); // 'spacious'

// Reset to auto-detect
RSL.Density.reset(layout);

// Detect pointer type
const pointer = RSL.Density.detectPointer();
console.log(pointer); // 'fine' or 'coarse'

// Available density levels
console.log(RSL.Density.levels);
// { COMPACT: 'compact', STANDARD: 'standard', SPACIOUS: 'spacious' }