๐ What Are auto-fill and auto-fit?
Both auto-fill and auto-fit are used with repeat() in grid-template-columns to create responsive, fluid grid layouts.
They allow grid items to auto-fit the available space based on a defined minimum and maximum size.
๐ง Syntax
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));or
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));๐ Visual Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS Grid: auto-fill</title>
<style>
.infographic-autofill {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-autofill[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.af-inner { padding: 0.5rem; }
.af-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.af-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.af-filebar {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
padding: 0.6rem 1rem;
}
.af-filename {
color: #ffffff;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
}
.af-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.8rem;
line-height: 1.85;
overflow-x: auto;
}
.af-line { display: block; white-space: pre; color: #e5e5e5; padding: 0.05rem 0.4rem; border-radius: 5px; }
.af-line.af-hl { background: #1c2333; box-shadow: inset 3px 0 0 #5b8def; color: #ffffff; }
.af-sel { color: #f472b6; font-weight: 700; }
.af-prop { color: #c586c0; }
.af-val { color: #ce9178; }
.af-com { color: #6a6a6a; font-style: italic; }
.af-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.af-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.af-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.af-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.af-controlrow {
background: var(--paper-alt);
padding: 0.5rem 0.7rem 0.7rem;
display: flex;
align-items: center;
gap: 0.7rem;
}
.af-control-label {
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
white-space: nowrap;
}
.af-slider {
flex: 1;
accent-color: var(--accent);
cursor: pointer;
}
.af-width-readout {
font-size: 0.72rem;
color: var(--ink);
font-weight: 700;
font-family: "SFMono-Regular", Consolas, monospace;
min-width: 46px;
text-align: right;
}
.af-screen {
background: #ffffff;
padding: 1.2rem 1.4rem 1.4rem;
overflow-x: auto;
}
.af-out-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
gap: 1rem;
width: 420px;
max-width: 100%;
transition: width 0.15s ease;
border: 1px dashed var(--line);
padding: 6px;
box-sizing: border-box;
}
.af-out-item {
background: #fff;
padding: 20px 10px;
text-align: center;
border: 1px solid #ccc;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
color: #1a1a1a;
font-weight: 600;
font-size: 0.85rem;
box-sizing: border-box;
}
.af-ghost {
border: 1px dashed #b8b0a0;
background: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(0,0,0,0.03) 6px, rgba(0,0,0,0.03) 12px);
box-shadow: none;
color: var(--ink-soft);
font-size: 0.68rem;
font-style: italic;
}
.af-readout {
font-size: 0.82rem;
color: var(--ink-soft);
padding: 0 0.2rem;
}
.af-readout strong { color: var(--ink); }
.af-readout code {
font-family: "SFMono-Regular", Consolas, monospace;
background: var(--paper-alt);
padding: 0.05rem 0.3rem;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="infographic-autofill" id="af-root">
<div class="af-inner">
<div class="af-layout">
<div class="af-code-wrap">
<div class="af-filebar"><span class="af-filename">style.css</span></div>
<div class="af-code">
<span class="af-line af-hl" id="af-css-line"> <span class="af-prop">grid-template-columns</span>: <span class="af-val">repeat(auto-fill, minmax(120px, 1fr))</span>;</span>
<span class="af-line"> <span class="af-prop">gap</span>: <span class="af-val">1rem</span>;</span>
<span class="af-line"><span class="af-com">/* only 3 .item elements exist in the HTML */</span></span>
</div>
</div>
<div class="af-browser">
<div class="af-browser-bar">
<span class="af-dot"></span><span class="af-dot"></span><span class="af-dot"></span>
<div class="af-tab">๐ CSS Grid - auto-fill</div>
</div>
<div class="af-controlrow">
<span class="af-control-label">container width</span>
<input type="range" class="af-slider" id="af-slider" min="180" max="760" step="10" value="420">
<span class="af-width-readout" id="af-width-readout">420px</span>
</div>
<div class="af-screen">
<div class="af-out-grid" id="af-out-grid">
<div class="af-out-item">Item 1</div>
<div class="af-out-item">Item 2</div>
<div class="af-out-item">Item 3</div>
</div>
</div>
</div>
<div class="af-readout" id="af-note">
<strong>auto-fill</strong> keeps creating <code>120px</code>-minimum tracks to fit the container โ even ones with nothing in them. Drag the slider wider and watch empty (dashed) tracks appear instead of the 3 items stretching to fill the space.
</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('af-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const slider = document.getElementById('af-slider');
const readout = document.getElementById('af-width-readout');
const grid = document.getElementById('af-out-grid');
const note = document.getElementById('af-note');
const MIN_TRACK = 120;
const GAP = 16; // 1rem
function render() {
const width = parseInt(slider.value, 10);
readout.textContent = width + 'px';
grid.style.width = width + 'px';
// Compute how many auto-fill tracks the browser would create
let cols = Math.floor((width + GAP) / (MIN_TRACK + GAP));
if (cols < 1) cols = 1;
// Rebuild: 3 real items + ghost tracks for the rest
grid.querySelectorAll('.af-ghost').forEach(g => g.remove());
const ghostCount = Math.max(0, cols - 3);
for (let i = 0; i < ghostCount; i++) {
const g = document.createElement('div');
g.className = 'af-out-item af-ghost';
g.textContent = 'empty track';
grid.appendChild(g);
}
if (ghostCount > 0) {
note.innerHTML = '<strong>' + cols + ' tracks</strong> fit at ' + width + 'px, but only 3 items exist โ <strong>' + ghostCount + '</strong> tracks stay reserved and empty (dashed) instead of the items stretching wider.';
} else {
note.innerHTML = 'At ' + width + 'px only <strong>' + cols + ' track' + (cols === 1 ? '' : 's') + '</strong> fit โ every track is filled, so items wrap or fill the row exactly.';
}
}
slider.addEventListener('input', render);
render();
})();
</script>
</body>
</html>๐น auto-fill - Keep space for empty columns
It fills the row with as many columns as possible, even if some are empty.
Empty tracks will still take up space.
โก๏ธ Creates as many 200px columns as will fit, including space for empty ones.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS Grid: auto-fill (200px tracks)</title>
<style>
.infographic-autofill2 {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-autofill2[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.af2-inner { padding: 0.5rem; }
.af2-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.af2-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.af2-filebar {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
padding: 0.6rem 1rem;
}
.af2-filename {
color: #ffffff;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
}
.af2-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.8rem;
line-height: 1.85;
overflow-x: auto;
}
.af2-line { display: block; white-space: pre; color: #e5e5e5; padding: 0.05rem 0.4rem; border-radius: 5px; }
.af2-line.af2-hl { background: #1c2333; box-shadow: inset 3px 0 0 #5b8def; color: #ffffff; }
.af2-sel { color: #f472b6; font-weight: 700; }
.af2-prop { color: #c586c0; }
.af2-val { color: #ce9178; }
.af2-com { color: #6a6a6a; font-style: italic; }
.af2-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.af2-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.af2-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.af2-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.af2-controlrow {
background: var(--paper-alt);
padding: 0.5rem 0.7rem 0.7rem;
display: flex;
align-items: center;
gap: 0.7rem;
}
.af2-control-label {
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
white-space: nowrap;
}
.af2-slider {
flex: 1;
accent-color: var(--accent);
cursor: pointer;
}
.af2-width-readout {
font-size: 0.72rem;
color: var(--ink);
font-weight: 700;
font-family: "SFMono-Regular", Consolas, monospace;
min-width: 46px;
text-align: right;
}
.af2-screen {
background: #ffffff;
padding: 1.2rem 1.4rem 1.4rem;
overflow-x: auto;
}
.af2-out-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 0px;
width: 620px;
max-width: 100%;
transition: width 0.15s ease;
border: 1px dashed var(--line);
box-sizing: border-box;
}
.af2-out-item {
background: #a2d2ff;
padding: 30px 10px;
text-align: center;
border: 1px solid #333;
color: #1a1a1a;
font-weight: 700;
font-size: 0.85rem;
box-sizing: border-box;
}
.af2-ghost {
border: 1px dashed #b8b0a0;
background: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(0,0,0,0.04) 6px, rgba(0,0,0,0.04) 12px);
color: var(--ink-soft);
font-size: 0.68rem;
font-style: italic;
font-weight: 400;
}
.af2-readout {
font-size: 0.82rem;
color: var(--ink-soft);
padding: 0 0.2rem;
}
.af2-readout strong { color: var(--ink); }
.af2-readout code {
font-family: "SFMono-Regular", Consolas, monospace;
background: var(--paper-alt);
padding: 0.05rem 0.3rem;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="infographic-autofill2" id="af2-root">
<div class="af2-inner">
<div class="af2-layout">
<div class="af2-code-wrap">
<div class="af2-filebar"><span class="af2-filename">style.css</span></div>
<div class="af2-code">
<span class="af2-line"><span class="af2-sel">.grid-auto-fill</span> {</span>
<span class="af2-line"> <span class="af2-prop">display</span>: <span class="af2-val">grid</span>;</span>
<span class="af2-line af2-hl" id="af2-css-line"> <span class="af2-prop">grid-template-columns</span>: <span class="af2-val">repeat(auto-fill, minmax(200px, 1fr))</span>;</span>
<span class="af2-line">}</span>
<span class="af2-line"><span class="af2-com">/* no gap set โ tracks butt up against each other */</span></span>
</div>
</div>
<div class="af2-browser">
<div class="af2-browser-bar">
<span class="af2-dot"></span><span class="af2-dot"></span><span class="af2-dot"></span>
<div class="af2-tab">๐ CSS Grid - auto-fill</div>
</div>
<div class="af2-controlrow">
<span class="af2-control-label">container width</span>
<input type="range" class="af2-slider" id="af2-slider" min="200" max="900" step="10" value="620">
<span class="af2-width-readout" id="af2-width-readout">620px</span>
</div>
<div class="af2-screen">
<div class="af2-out-grid" id="af2-out-grid">
<div class="af2-out-item">Item 1</div>
<div class="af2-out-item">Item 2</div>
<div class="af2-out-item">Item 3</div>
</div>
</div>
</div>
<div class="af2-readout" id="af2-note">
Each track now needs at least <strong>200px</strong> โ a wider minimum than before, so fewer tracks fit in the same space. Drag the slider and watch the empty-track count change.
</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('af2-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const slider = document.getElementById('af2-slider');
const readout = document.getElementById('af2-width-readout');
const grid = document.getElementById('af2-out-grid');
const note = document.getElementById('af2-note');
const MIN_TRACK = 200;
const GAP = 0;
function render() {
const width = parseInt(slider.value, 10);
readout.textContent = width + 'px';
grid.style.width = width + 'px';
let cols = Math.floor((width + GAP) / (MIN_TRACK + GAP));
if (cols < 1) cols = 1;
grid.querySelectorAll('.af2-ghost').forEach(g => g.remove());
const ghostCount = Math.max(0, cols - 3);
for (let i = 0; i < ghostCount; i++) {
const g = document.createElement('div');
g.className = 'af2-out-item af2-ghost';
g.textContent = 'empty track';
grid.appendChild(g);
}
if (ghostCount > 0) {
note.innerHTML = '<strong>' + cols + ' tracks</strong> of 200px fit at ' + width + 'px, but only 3 items exist โ <strong>' + ghostCount + '</strong> stay empty instead of the items stretching wider.';
} else {
note.innerHTML = 'At ' + width + 'px only <strong>' + cols + ' track' + (cols === 1 ? '' : 's') + '</strong> of 200px fit โ no room left over, so every track holds an item.';
}
}
slider.addEventListener('input', render);
render();
})();
</script>
</body>
</html>๐น auto-fit - Collapse empty columns
Works like
auto-fillbut collapses the empty columns.Great for layouts that should not show gaps when items are missing.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS Grid: auto-fit</title>
<style>
.infographic-autofit {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-autofit[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.at-inner { padding: 0.5rem; }
.at-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.at-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.at-filebar {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
padding: 0.6rem 1rem;
}
.at-filename {
color: #ffffff;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
}
.at-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.8rem;
line-height: 1.85;
overflow-x: auto;
}
.at-line { display: block; white-space: pre; color: #e5e5e5; padding: 0.05rem 0.4rem; border-radius: 5px; }
.at-line.at-hl { background: #1c2333; box-shadow: inset 3px 0 0 #5b8def; color: #ffffff; }
.at-sel { color: #f472b6; font-weight: 700; }
.at-prop { color: #c586c0; }
.at-val { color: #ce9178; }
.at-com { color: #6a6a6a; font-style: italic; }
.at-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.at-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.at-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.at-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.at-controlrow {
background: var(--paper-alt);
padding: 0.5rem 0.7rem 0.7rem;
display: flex;
align-items: center;
gap: 0.7rem;
flex-wrap: wrap;
}
.at-control-label {
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
white-space: nowrap;
}
.at-slider {
flex: 1;
min-width: 100px;
accent-color: var(--accent);
cursor: pointer;
}
.at-width-readout {
font-size: 0.72rem;
color: var(--ink);
font-weight: 700;
font-family: "SFMono-Regular", Consolas, monospace;
min-width: 46px;
text-align: right;
}
.at-mode-toggle {
display: flex;
border: 1px solid var(--line);
border-radius: 999px;
overflow: hidden;
flex-shrink: 0;
}
.at-mode-btn {
border: none;
background: var(--paper);
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 0.68rem;
font-weight: 700;
padding: 0.3rem 0.6rem;
cursor: pointer;
}
.at-mode-btn.at-mode-on { background: var(--accent); color: #ffffff; }
.at-screen {
background: #ffffff;
padding: 1.2rem 1.4rem 1.4rem;
overflow-x: auto;
}
.at-out-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 0px;
width: 620px;
max-width: 100%;
transition: width 0.15s ease;
border: 1px dashed var(--line);
box-sizing: border-box;
}
.at-out-item {
background: #a2d2ff;
padding: 30px 10px;
text-align: center;
border: 1px solid #333;
color: #1a1a1a;
font-weight: 700;
font-size: 0.85rem;
box-sizing: border-box;
}
.at-ghost {
border: 1px dashed #b8b0a0;
background: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(0,0,0,0.04) 6px, rgba(0,0,0,0.04) 12px);
color: var(--ink-soft);
font-size: 0.68rem;
font-style: italic;
font-weight: 400;
}
.at-readout {
font-size: 0.82rem;
color: var(--ink-soft);
padding: 0 0.2rem;
}
.at-readout strong { color: var(--ink); }
.at-readout code {
font-family: "SFMono-Regular", Consolas, monospace;
background: var(--paper-alt);
padding: 0.05rem 0.3rem;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="infographic-autofit" id="at-root">
<div class="at-inner">
<div class="at-layout">
<div class="at-code-wrap">
<div class="at-filebar"><span class="at-filename">style.css</span></div>
<div class="at-code">
<span class="at-line"><span class="at-sel">.grid-auto-fill</span> {</span>
<span class="at-line"> <span class="at-prop">display</span>: <span class="at-val">grid</span>;</span>
<span class="at-line at-hl" id="at-css-line"> <span class="at-prop">grid-template-columns</span>: <span class="at-val">repeat(auto-fit, minmax(200px, 1fr))</span>;</span>
<span class="at-line">}</span>
</div>
</div>
<div class="at-browser">
<div class="at-browser-bar">
<span class="at-dot"></span><span class="at-dot"></span><span class="at-dot"></span>
<div class="at-tab">๐ CSS Grid - auto-fit</div>
</div>
<div class="at-controlrow">
<span class="at-control-label">width</span>
<input type="range" class="at-slider" id="at-slider" min="200" max="900" step="10" value="620">
<span class="at-width-readout" id="at-width-readout">620px</span>
</div>
<div class="at-screen">
<div class="at-out-grid" id="at-out-grid">
<div class="at-out-item">Item 1</div>
<div class="at-out-item">Item 2</div>
<div class="at-out-item">Item 3</div>
</div>
</div>
</div>
<div class="at-readout" id="at-note">
<strong>auto-fit</strong> collapses any empty tracks to <code>0</code> width and lets the 1fr items stretch to absorb the leftover space โ 3 items, 3 tracks, always.
</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('at-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const slider = document.getElementById('at-slider');
const readout = document.getElementById('at-width-readout');
const grid = document.getElementById('at-out-grid');
const note = document.getElementById('at-note');
function render() {
const width = parseInt(slider.value, 10);
readout.textContent = width + 'px';
grid.style.width = width + 'px';
note.innerHTML = '<strong>auto-fit</strong> collapses empty tracks to 0 width, so the 3 items stretch to fill ' + width + 'px between them โ always 3 columns, never empty ones.';
}
slider.addEventListener('input', render);
render();
})();
</script>
</body>
</html>โ Summary
Term | Meaning |
|---|---|
| Fills grid row with possible columns (reserves space for empty ones) |
| Fits only filled columns, collapsing the empty ones |
| Sets min/max size for columns |