Truly fluid responsive grids with CSS Grid's auto-fit and auto-fill
Auto-fit and auto-fill are powerful CSS Grid features that automatically create as many columns as will fit in the container, each with a minimum and maximum size. This creates truly responsive layouts that adapt to any screen size without media queries.
Collapses empty tracks: If you have fewer items than columns can fit, auto-fit will collapse the empty tracks and expand the filled ones.
data-auto-fit="250px"
Equivalent to: repeat(auto-fit, minmax(250px, 1fr))
Keeps empty tracks: Creates as many columns as will fit, even if empty. Useful when you want consistent grid structure regardless of item count.
data-auto-fill="250px"
Equivalent to: repeat(auto-fill, minmax(250px, 1fr))
The most common use case. Columns will be at least 250px wide and expand to fill available space. Resize your browser to see the grid adapt automatically.
<div class="slot-layout" data-auto-fit="250px">
<div class="slot-item">Item 1</div>
<div class="slot-item">Item 2</div>
<div class="slot-item">Item 3</div>
<!-- Automatically creates columns that are at least 250px -->
</div>
With 3 items in a wide container, notice how auto-fit expands items to fill the space, while auto-fill maintains the column structure.
RSL provides common presets: 150px, 200px, 250px, 300px, 350px, 400px
For sizes not in the presets, use CSS variables:
<div class="slot-layout" style="--min-col-width: 280px; --max-col-width: 1fr">
<div class="slot-item">Item 1</div>
<div class="slot-item">Item 2</div>
</div>
<!-- Or in CSS -->
<style>
.my-grid {
--min-col-width: 280px;
--max-col-width: 500px; /* Max width instead of 1fr */
}
</style>
Auto-fit/auto-fill works great with RSL's gap control attributes:
<div class="slot-layout" data-auto-fit="200px" data-gap="spacious">
<!-- Combines auto-fit with 2rem gap -->
</div>
data-auto-fit="150px" - Minimum 150px columnsdata-auto-fit="200px" - Minimum 200px columnsdata-auto-fit="250px" - Minimum 250px columns (recommended)data-auto-fit="300px" - Minimum 300px columnsdata-auto-fit="350px" - Minimum 350px columnsdata-auto-fit="400px" - Minimum 400px columnsdata-auto-fill="150px" through data-auto-fill="400px"