Responsive card grid
LayoutCards that find their own column count, with useful minimum widths and no layout script.
HTML + CSS · No JavaScript
repeat(auto-fit, minmax(min(100%, 16rem), 1fr)) Layout · Complete runnable example
A horizontal collection that moves only when the reader asks it to.
This preview runs in an isolated document. Clipboard writes and saved preferences may be blocked, and printing requires the standalone file. A dialog affects only the example. Reset reloads the original example state.
Use this pattern for a short collection where one card at a time suits the content. The underlying ordered list stays readable and horizontally scrollable without JavaScript.
The preview, copied text, and downloaded file use this same document.
<!doctype html>
<!--
MIT License
Copyright (c) 2026 MRHTML
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data: blob:; connect-src 'none'; form-action 'none'; object-src 'none'; base-uri 'none'"
/>
<title>MRHTML | Move at your own pace.</title>
<style>
:root {
font-family: Arial, Helvetica, sans-serif;
color-scheme: light;
--ink: #192f34;
--muted: #56666a;
--paper: #f6f5f0;
--line: #cdd5d0;
--accent: #186354;
--soft: #e7efe5;
--mono: Consolas, 'Liberation Mono', monospace;
}
* {
box-sizing: border-box;
}
html {
scroll-padding-top: 90px;
}
body {
margin: 0;
background: var(--paper);
color: var(--ink);
line-height: 1.6;
}
h1,
h2,
h3,
p {
margin: 0;
}
h1,
h2,
h3 {
font-weight: 500;
letter-spacing: -0.045em;
line-height: 1.1;
}
h1 {
font-size: clamp(38px, 5.5vw, 65px);
}
h2 {
font-size: 29px;
}
h3 {
font-size: 21px;
}
p {
overflow-wrap: anywhere;
}
a {
color: var(--accent);
text-underline-offset: 4px;
}
button,
select {
font: inherit;
color: inherit;
}
button {
cursor: pointer;
}
button,
a,
summary {
touch-action: manipulation;
}
button:focus-visible,
a:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
outline: 3px solid #a94823;
outline-offset: 4px;
}
[hidden] {
display: none !important;
}
.wrap {
width: min(1050px, calc(100% - 64px));
margin-inline: auto;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
padding: 28px 0;
border-bottom: 1px solid var(--line);
}
.brand {
font-size: 15px;
font-weight: 700;
display: flex;
align-items: center;
gap: 10px;
letter-spacing: -0.5px;
}
.mark {
display: grid;
place-items: center;
width: 28px;
height: 28px;
background: var(--accent);
color: #fff;
font-weight: bold;
font-size: 18px;
}
.header > p,
.eyebrow,
.small {
font: 10px/1.7 var(--mono);
letter-spacing: 0.03em;
}
.header > p {
color: var(--muted);
}
main {
padding-block: 43px 50px;
}
.intro {
margin-bottom: 30px;
max-width: 720px;
}
.eyebrow {
color: var(--accent);
margin-bottom: 13px;
}
.intro > p:last-child {
font-size: 15px;
max-width: 570px;
color: var(--muted);
margin-top: 18px;
}
.surface {
background: #fff;
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 12px 32px #263e3010;
}
.button {
border: 1px solid var(--accent);
background: var(--accent);
color: #fff;
padding: 10px 16px;
min-height: 43px;
border-radius: 7px;
font-size: 13px;
font-weight: 600;
}
.button.secondary {
background: #fff;
color: var(--accent);
border-color: #a9bbb0;
}
.button[aria-disabled='true'],
button:disabled {
background: #edf0e9;
color: #5d695f;
border-color: #c9d1c4;
cursor: default;
}
.status {
font-size: 12px;
color: var(--muted);
min-height: 22px;
}
.note {
font-size: 12px;
color: var(--muted);
margin-top: 20px;
max-width: 75ch;
}
.footer {
display: flex;
justify-content: space-between;
gap: 20px;
padding-block: 22px;
border-top: 1px solid var(--line);
font-size: 10px;
color: var(--muted);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
noscript p {
padding: 15px;
background: #e8ece2;
border-left: 3px solid var(--accent);
font-size: 13px;
margin-bottom: 20px;
}
code,
kbd {
font: 12px var(--mono);
}
kbd {
border: 1px solid #bcc7bd;
border-radius: 4px;
padding: 2px 5px;
background: #fff;
}
button:disabled:focus {
outline: none;
}
@media (max-width: 600px) {
.wrap {
width: calc(100% - 36px);
}
.header {
padding-block: 22px;
}
.header > p {
font-size: 8px;
max-width: 105px;
text-align: right;
}
.brand {
font-size: 13px;
gap: 8px;
}
main {
padding-block: 30px 35px;
}
.intro {
margin-bottom: 26px;
}
.intro > p:last-child {
font-size: 14px;
}
.eyebrow {
font-size: 9px;
}
h1 {
font-size: 40px;
}
.footer {
flex-wrap: wrap;
font-size: 9px;
}
}
@media (max-width: 350px) {
h1 {
font-size: 35px;
}
.button {
padding: 10px 12px;
font-size: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
.slides {
list-style: none;
display: flex;
gap: 18px;
overflow-x: auto;
scroll-snap-type: x mandatory;
overscroll-behavior-x: contain;
margin: 0;
padding: 0 0 15px;
position: relative;
border-radius: 12px;
scrollbar-color: #677d67 #e1e7db;
}
.slide {
flex: 0 0 100%;
min-width: 0;
scroll-snap-align: start;
scroll-snap-stop: always;
border: 1px solid #c2cbb7;
border-radius: 12px;
background: #e7edda;
}
.slide article {
padding: 32px;
}
.slide .small {
color: #3e583e;
font-size: 10px;
}
.slide-grid {
display: grid;
grid-template-columns: 1.2fr 1fr;
gap: 35px;
align-items: center;
padding: 27px 0 17px;
}
.slide-kicker {
font: 11px var(--mono);
text-transform: uppercase;
color: #43623d;
margin-bottom: 18px;
}
.slide h2 {
font-size: clamp(33px, 4.8vw, 59px);
line-height: 1.02;
}
.slide-copy {
font-size: 14px;
color: #495a43;
max-width: 30ch;
margin-top: 23px;
}
.slide-art {
position: relative;
height: 235px;
display: grid;
place-items: center;
}
.slide-art i {
position: absolute;
border: 1px solid #63714e;
width: 180px;
height: 180px;
border-radius: 50%;
}
.slide-art i:nth-child(2) {
width: 130px;
height: 130px;
background: #a9b982;
}
.slide-art i:nth-child(3) {
width: 60px;
height: 60px;
background: #305b42;
border: none;
}
.tone-b {
background: #e2e8f5;
border-color: #bcc8e1;
}
.tone-b .slide-art i {
border-radius: 9px;
border-color: #536b97;
transform: rotate(18deg);
}
.tone-b .slide-art i:nth-child(2) {
background: #a5b7df;
transform: rotate(-18deg);
}
.tone-b .slide-art i:nth-child(3) {
background: #31558d;
}
.tone-b .small,
.tone-b .slide-kicker,
.tone-b .slide-copy {
color: #475775;
}
.tone-c {
background: #f2e3c8;
border-color: #d2b991;
}
.tone-c .slide-art i {
border-radius: 100px 100px 0 0;
border-color: #976536;
}
.tone-c .slide-art i:nth-child(2) {
background: #d9b274;
transform: translate(25px, 20px);
}
.tone-c .slide-art i:nth-child(3) {
background: #835332;
transform: translate(-35px, -35px);
}
.tone-c .small,
.tone-c .slide-kicker,
.tone-c .slide-copy {
color: #6f553b;
}
.tone-d {
background: #e8dfe9;
border-color: #cdb3cc;
}
.tone-d .slide-art i {
border-radius: 0;
transform: rotate(45deg);
border-color: #8a658b;
}
.tone-d .slide-art i:nth-child(2) {
background: #bba2c0;
}
.tone-d .slide-art i:nth-child(3) {
background: #745179;
}
.tone-d .small,
.tone-d .slide-kicker,
.tone-d .slide-copy {
color: #6a4b6b;
}
.carousel-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-top: 18px;
}
.controls {
display: flex;
gap: 10px;
}
@media (max-width: 600px) {
.slide article {
padding: 24px;
}
.slide-grid {
grid-template-columns: 1fr;
gap: 15px;
padding-top: 23px;
}
.slide h2 {
font-size: 39px;
}
.slide-copy {
font-size: 13px;
margin-top: 17px;
}
.slide-art {
height: 200px;
}
.slide-art i {
width: 155px;
height: 155px;
}
.slide-art i:nth-child(2) {
width: 110px;
height: 110px;
}
.slide-art i:nth-child(3) {
width: 50px;
height: 50px;
}
.carousel-foot {
flex-wrap: wrap;
gap: 16px;
}
.controls {
gap: 8px;
}
.controls .button {
font-size: 12px;
}
.carousel-foot .status {
font-size: 11px;
}
}
</style>
</head>
<body>
<header class="header wrap">
<span class="brand"
><span class="mark" aria-hidden="true">m.</span>MRHTML / Workshop</span
>
<p>SMALL PATTERNS.<br />CONSIDERED DETAILS.</p>
</header>
<main class="wrap">
<div class="intro">
<p class="eyebrow">04 / MANUAL SCROLL SNAP</p>
<h1>Move at your own pace.</h1>
<p>
Four small prompts for a creative afternoon. Swipe, scroll, or use the
controls. Nothing advances on its own.
</p>
</div>
<noscript
><p>
All four cards remain in the scrollable track. Scroll horizontally or
use a touch swipe to read them.
</p></noscript
>
<section class="carousel" aria-label="Creative field cards">
<ol
id="slides"
class="slides"
tabindex="0"
aria-label="Four field cards, horizontally scrollable"
>
<li class="slide tone-a">
<article>
<p class="small">FIELD CARD / 01</p>
<div class="slide-grid">
<div>
<p class="slide-kicker">Notice</p>
<h2>Start with the<br />small things.</h2>
<p class="slide-copy">
Find a detail you would usually walk past.
</p>
</div>
<div class="slide-art" aria-hidden="true">
<i></i><i></i><i></i>
</div>
</div>
</article>
</li>
<li class="slide tone-b">
<article>
<p class="small">FIELD CARD / 02</p>
<div class="slide-grid">
<div>
<p class="slide-kicker">Collect</p>
<h2>Give curiosity<br />some room.</h2>
<p class="slide-copy">
Keep a few questions before choosing an answer.
</p>
</div>
<div class="slide-art" aria-hidden="true">
<i></i><i></i><i></i>
</div>
</div>
</article>
</li>
<li class="slide tone-c">
<article>
<p class="small">FIELD CARD / 03</p>
<div class="slide-grid">
<div>
<p class="slide-kicker">Connect</p>
<h2>Look for<br />the thread.</h2>
<p class="slide-copy">
Find the idea that helps the pieces make sense.
</p>
</div>
<div class="slide-art" aria-hidden="true">
<i></i><i></i><i></i>
</div>
</div>
</article>
</li>
<li class="slide tone-d">
<article>
<p class="small">FIELD CARD / 04</p>
<div class="slide-grid">
<div>
<p class="slide-kicker">Make</p>
<h2>Try a modest<br />first version.</h2>
<p class="slide-copy">
Make something small enough to learn from.
</p>
</div>
<div class="slide-art" aria-hidden="true">
<i></i><i></i><i></i>
</div>
</div>
</article>
</li>
</ol>
<div class="carousel-foot" id="carousel-controls" hidden>
<div class="controls">
<button
type="button"
class="button secondary"
id="previous"
aria-controls="slides"
>
← Previous</button
><button
type="button"
class="button secondary"
id="next"
aria-controls="slides"
>
Next →
</button>
</div>
<p
id="slide-status"
class="status"
role="status"
aria-live="polite"
aria-atomic="true"
>
Card 1 of 4
</p>
</div>
</section>
<p class="note">
Focus the card track to use Left, Right, Home, or End. Native horizontal
scrolling stays available, including without JavaScript.
</p>
</main>
<footer class="footer wrap">
<span>MRHTML / Original runnable example</span
><span>Local content. No network required.</span>
</footer>
<script>
(() => {
'use strict';
const track = document.querySelector('#slides'),
slides = [...track.children];
const previous = document.querySelector('#previous'),
next = document.querySelector('#next');
let index = 0,
targetIndex = null,
frame = 0,
settle = 0;
const reduced = matchMedia('(prefers-reduced-motion: reduce)');
function position(item) {
return item.offsetLeft - slides[0].offsetLeft;
}
function update() {
index = slides.reduce(
(best, slide, i) =>
Math.abs(position(slide) - track.scrollLeft) <
Math.abs(position(slides[best]) - track.scrollLeft)
? i
: best,
0,
);
const pending = targetIndex === null ? index : targetIndex;
previous.setAttribute('aria-disabled', String(pending === 0));
next.setAttribute(
'aria-disabled',
String(pending === slides.length - 1),
);
clearTimeout(settle);
settle = setTimeout(() => {
targetIndex = null;
previous.setAttribute('aria-disabled', String(index === 0));
next.setAttribute(
'aria-disabled',
String(index === slides.length - 1),
);
document.querySelector('#slide-status').textContent =
`Card ${index + 1} of ${slides.length}: ${slides[index].querySelector('.slide-kicker').textContent}.`;
}, 120);
}
function go(target, smooth = true) {
targetIndex = Math.max(0, Math.min(slides.length - 1, target));
track.scrollTo({
left: position(slides[targetIndex]),
behavior: smooth && !reduced.matches ? 'smooth' : 'auto',
});
update();
}
previous.addEventListener('click', () => {
if (previous.getAttribute('aria-disabled') !== 'true')
go((targetIndex === null ? index : targetIndex) - 1);
});
next.addEventListener('click', () => {
if (next.getAttribute('aria-disabled') !== 'true')
go((targetIndex === null ? index : targetIndex) + 1);
});
track.addEventListener('keydown', (event) => {
if (event.target !== track) return;
let target;
if (event.key === 'ArrowRight')
target = (targetIndex === null ? index : targetIndex) + 1;
if (event.key === 'ArrowLeft')
target = (targetIndex === null ? index : targetIndex) - 1;
if (event.key === 'Home') target = 0;
if (event.key === 'End') target = slides.length - 1;
if (target !== undefined) {
event.preventDefault();
go(target);
}
});
track.addEventListener('pointerdown', () => {
targetIndex = null;
});
track.addEventListener(
'wheel',
() => {
targetIndex = null;
},
{ passive: true },
);
track.addEventListener(
'scroll',
() => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(update);
},
{ passive: true },
);
if ('ResizeObserver' in window)
new ResizeObserver(() =>
go(targetIndex === null ? index : targetIndex, false),
).observe(track);
else
window.addEventListener('resize', () =>
go(targetIndex === null ? index : targetIndex, false),
);
update();
document.querySelector('#carousel-controls').hidden = false;
})();
</script>
</body>
</html>