HTML used in this demo
<main class="layout-lab" data-layout-lab data-mode="grid" data-density="normal">
<header class="lab-header">
<p class="eyebrow">Layout decision</p>
<h1>Same content, different layout ownership</h1>
<p>Change the available slot and content pressure to see when the primitive becomes part of the maintenance problem.</p>
</header>
<form class="control-panel" aria-label="Layout behavior controls">
<fieldset class="control-group">
<legend>Layout mode</legend>
<div class="segmented">
<label><input type="radio" name="mode" value="flex" /> Flex wrap</label>
<label><input type="radio" name="mode" value="grid" checked /> Grid tracks</label>
<label><input type="radio" name="mode" value="query" /> Container query</label>
</div>
</fieldset>
<label class="control-group">
<span>Content pressure</span>
<select name="density">
<option value="normal">Normal cards</option>
<option value="dense">Dense metadata</option>
<option value="long">Long production labels</option>
</select>
</label>
<label class="control-group">
<span>Component slot <strong data-width-label>760px</strong></span>
<input type="range" name="width" min="360" max="860" value="760" />
</label>
</form>
<section class="stage" aria-label="Layout preview">
<div class="stage__measure" data-stage>
<div class="work-list">
<article class="work-card work-card--primary">
<div>
<p class="work-card__meta">Release risk</p>
<h2 data-card-title>Checkout summary</h2>
</div>
<p class="work-card__detail">Needs amount, tax, discount, and payment method visible before confirmation.</p>
<a href="#preview">Review</a>
</article>
<article class="work-card">
<div>
<p class="work-card__meta">Support queue</p>
<h2 data-card-title>Refund states</h2>
</div>
<p class="work-card__detail">Includes pending, partial, failed, and manual approval states.</p>
<a href="#preview">Inspect</a>
</article>
<article class="work-card">
<div>
<p class="work-card__meta">Localization</p>
<h2 data-card-title>German labels</h2>
</div>
<p class="work-card__detail">Longest strings should wrap without pushing actions out of reach.</p>
<a href="#preview">Compare</a>
</article>
</div>
</div>
</section>
<aside class="diagnosis" aria-live="polite">
<p class="eyebrow">Reading the result</p>
<h2 data-verdict>Grid is the strongest default here.</h2>
<p data-reason>Cards need predictable columns and aligned actions, so the two-axis relationship matters more than simple distribution.</p>
<ul data-checks>
<li>Tracks absorb unequal text without changing the component contract.</li>
<li>Actions remain visually comparable across rows.</li>
</ul>
</aside>
</main>
CSS used in this demo
.layout-lab {
--ink: #17212b;
--muted: #526160;
--line: #c8d4d1;
--surface: #fffdf8;
--panel: #f2f7f4;
--accent: #0d6f67;
display: grid;
gap: 1rem;
max-width: 68rem;
margin: 0 auto;
padding: 1.25rem;
color: var(--ink);
}
.lab-header {
display: grid;
gap: 0.35rem;
max-width: 52rem;
}
.eyebrow,
.work-card__meta {
margin: 0;
color: var(--accent);
font-size: 0.76rem;
font-weight: 800;
letter-spacing: 0;
text-transform: uppercase;
}
h1,
h2,
p {
margin-block: 0;
}
h1 {
font-size: clamp(1.8rem, 5vw, 3.2rem);
line-height: 1.02;
}
.control-panel {
display: grid;
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
align-items: end;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--surface);
padding: 0.85rem;
}
.control-group {
display: grid;
gap: 0.45rem;
margin: 0;
border: 0;
padding: 0;
color: var(--muted);
font-weight: 700;
}
.control-group strong {
color: var(--ink);
}
.segmented {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
}
.segmented label {
position: relative;
min-height: 2.4rem;
border: 1px solid var(--line);
border-radius: 6px;
background: #ffffff;
padding: 0.55rem 0.7rem;
color: var(--ink);
cursor: pointer;
}
.segmented input {
position: absolute;
inline-size: 1px;
block-size: 1px;
opacity: 0;
}
.segmented label:has(input:checked) {
border-color: var(--accent);
background: #dff0ec;
}
select,
input[type='range'] {
width: 100%;
}
select {
min-height: 2.45rem;
border: 1px solid var(--line);
border-radius: 6px;
background: #ffffff;
padding-inline: 0.65rem;
}
input[type='range'] {
accent-color: var(--accent);
}
.stage {
border: 1px solid var(--line);
border-radius: 8px;
background: linear-gradient(90deg, #eef4f1 1px, transparent 1px), #f8faf8;
background-size: 24px 24px;
padding: 1rem;
overflow-x: auto;
}
.stage__measure {
--stage-width: 760px;
container-type: inline-size;
max-width: min(100%, var(--stage-width));
min-width: min(100%, 20rem);
margin-inline: auto;
border: 1px dashed #97aaa5;
border-radius: 8px;
background: rgba(255, 255, 255, 0.72);
padding: 0.75rem;
}
.work-list {
display: grid;
gap: 0.75rem;
}
.work-card {
display: grid;
gap: 0.8rem;
align-content: space-between;
min-width: 0;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--surface);
padding: 0.9rem;
}
.work-card h2 {
margin-block-start: 0.25rem;
font-size: 1.15rem;
line-height: 1.12;
overflow-wrap: anywhere;
}
.work-card__detail {
display: none;
color: var(--muted);
font-size: 0.92rem;
line-height: 1.45;
}
.work-card a {
justify-self: start;
border: 1px solid var(--ink);
border-radius: 6px;
color: var(--ink);
padding: 0.45rem 0.65rem;
text-decoration: none;
}
[data-density='dense'] .work-card__detail,
[data-density='long'] .work-card__detail {
display: block;
}
[data-mode='flex'] .work-list {
display: flex;
flex-wrap: wrap;
align-items: stretch;
}
[data-mode='flex'] .work-card {
flex: 1 1 14rem;
}
[data-mode='grid'] .work-list {
grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
}
[data-mode='query'] .work-list {
grid-template-columns: 1fr;
}
@container (min-width: 40rem) {
[data-mode='query'] .work-list {
grid-template-columns: 1.25fr 1fr;
}
[data-mode='query'] .work-card--primary {
grid-row: span 2;
}
}
@container (min-width: 58rem) {
[data-mode='query'] .work-list {
grid-template-columns: 1.4fr 1fr 1fr;
}
}
.diagnosis {
display: grid;
gap: 0.55rem;
border-inline-start: 4px solid var(--accent);
background: var(--panel);
padding: 0.95rem 1rem;
}
.diagnosis h2 {
font-size: 1.25rem;
}
.diagnosis ul {
display: grid;
gap: 0.35rem;
margin: 0;
padding-inline-start: 1.1rem;
color: var(--muted);
}
JavaScript used in this demo
const lab = document.querySelector('[data-layout-lab]');
const form = lab.querySelector('form');
const stage = lab.querySelector('[data-stage]');
const widthLabel = lab.querySelector('[data-width-label]');
const titles = Array.from(lab.querySelectorAll('[data-card-title]'));
const verdict = lab.querySelector('[data-verdict]');
const reason = lab.querySelector('[data-reason]');
const checks = lab.querySelector('[data-checks]');
const cardTitles = {
normal: ['Checkout summary', 'Refund states', 'German labels'],
dense: ['Checkout summary with applied promotions', 'Refund states across payment providers', 'German labels in account settings'],
long: [
'Checkout summary with unavailable payment methods and stacked promotion rules',
'Refund states across payment providers, manual review, and failed captures',
'German labels for account-level notification preferences and billing history',
],
};
const notes = {
flex: {
verdict: 'Flexbox is useful only while the job stays one-axis.',
reason: 'Wrapping distributes cards into available space, but row alignment becomes a side effect once content lengths diverge.',
checks: [
'Good for a toolbar or a loose list of chips.',
'Risky when cards need comparable columns, metadata, or action placement.',
],
},
grid: {
verdict: 'Grid is the strongest default here.',
reason: 'Cards need predictable columns and aligned actions, so the two-axis relationship matters more than simple distribution.',
checks: [
'Tracks absorb unequal text without changing the component contract.',
'Actions remain visually comparable across rows.',
],
},
query: {
verdict: 'Container queries make the component own the breakpoint.',
reason: 'The preview changes at the card rail width, not at the viewport, which is the safer rule for reusable components.',
checks: [
'Use this when the same component appears in a sidebar, modal, and wide page slot.',
'Keep page-level media queries for the surrounding shell.',
],
},
};
function renderList(items) {
checks.replaceChildren();
items.forEach((item) => {
const li = document.createElement('li');
li.textContent = item;
checks.append(li);
});
}
function render() {
const values = new FormData(form);
const mode = values.get('mode') || 'grid';
const density = values.get('density') || 'normal';
const width = Number(values.get('width') || 760);
const activeNotes = notes[mode];
lab.dataset.mode = mode;
lab.dataset.density = density;
stage.style.setProperty('--stage-width', width + 'px');
widthLabel.textContent = width + 'px';
cardTitles[density].forEach((title, index) => {
titles[index].textContent = title;
});
verdict.textContent = activeNotes.verdict;
reason.textContent = activeNotes.reason;
const extraCheck = width < 520 && density !== 'normal'
? 'At this width, the layout also needs overflow-wrap, stable actions, and a clear wrapping policy.'
: 'The layout decision should still be tested with the longest expected content.';
renderList(activeNotes.checks.concat(extraCheck));
}
form.addEventListener('input', render);
render();