Layout · Complete runnable example

Responsive card grid

Cards that find their own column count, with useful minimum widths and no layout script.

Live example

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.

When to use it

Use this grid for a collection of projects, resources, or articles whose count can change. The layout works with the cards in the document and lets their order remain the same for reading and keyboard navigation.

Try the important details

  1. Switch between available width, tablet, and mobile to watch columns adapt.
  2. Tab through the native reading controls and confirm that focus follows the document order.
  3. Try longer titles or remove cards in your downloaded file; the layout should still fit its container.

How it works

  • auto-fit creates as many columns as fit, then collapses unused tracks.
  • The inner min(100%, 16rem) prevents a minimum card width from exceeding a narrow container.
  • Semantic headings and native details controls carry the content. Visual layout does not reorder the document.

The complete source

The preview, copied text, and downloaded file use this same document.

HTML

<!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:; connect-src 'none'; form-action 'none'; object-src 'none'; base-uri 'none'"
    />
    <title>MRHTML | A responsive card grid</title>
    <style>
      :root {
        color-scheme: light;
        --paper: #f6f5f0;
        --white: #fff;
        --ink: #172437;
        --muted: #546171;
        --line: #c9ced4;
        --blue: #204cbb;
        --soft: #e9eefb;
        font-family: Arial, Helvetica, sans-serif;
      }
      * {
        box-sizing: border-box;
      }
      body {
        margin: 0;
        background: var(--paper);
        color: var(--ink);
        line-height: 1.65;
      }
      main {
        width: min(72rem, calc(100% - 3rem));
        margin: 0 auto;
        padding: clamp(2rem, 6vw, 4.5rem) 0;
      }
      h1,
      h2,
      h3,
      p {
        margin: 0;
      }
      a {
        color: var(--blue);
        text-underline-offset: 0.25em;
      }
      a:focus-visible,
      button:focus-visible,
      summary:focus-visible,
      input:focus-visible {
        outline: 3px solid var(--blue);
        outline-offset: 4px;
      }
      .eyebrow {
        color: var(--blue);
        font-size: 0.72rem;
        font-weight: 700;
        letter-spacing: 0.15em;
        text-transform: uppercase;
      }
      h1 {
        font-size: clamp(2.3rem, 6vw, 4.2rem);
        letter-spacing: -0.055em;
        line-height: 1.08;
        max-width: 15ch;
        overflow-wrap: anywhere;
      }
      .intro {
        color: var(--muted);
        font-size: 1rem;
        max-width: 40rem;
        margin-top: 1.3rem;
      }
      .footer-note {
        margin-top: 2.5rem;
        border-top: 1px solid var(--line);
        padding-top: 1.25rem;
        color: var(--muted);
        font-size: 0.8rem;
      }
      [hidden] {
        display: none !important;
      }
      @media (max-width: 420px) {
        main {
          width: calc(100% - 2rem);
        }
      }
      @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
          scroll-behavior: auto !important;
          animation: none !important;
          transition: none !important;
        }
      }

      .masthead {
        flex-wrap: wrap;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        border-bottom: 1px solid var(--line);
        padding-bottom: 1rem;
        margin-bottom: 2.75rem;
      }
      .edition {
        font-size: 0.72rem;
        color: var(--muted);
        text-align: right;
      }
      .intro-heading {
        display: grid;
        grid-template-columns: 1.2fr 1fr;
        gap: 2rem;
        align-items: end;
        margin-bottom: 2.5rem;
      }
      .intro-heading .intro {
        margin: 0;
      }
      .card-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
        gap: 1.2rem;
      }
      .card {
        min-width: 0;
        background: var(--white);
        border: 1px solid var(--line);
        border-radius: 0.9rem;
        overflow: hidden;
        display: flex;
        flex-direction: column;
      }
      .card-art {
        height: 8rem;
        background: var(--soft);
        padding: 1.3rem;
        position: relative;
        overflow: hidden;
      }
      .art-label {
        position: relative;
        z-index: 1;
        font-size: 0.68rem;
        text-transform: uppercase;
        letter-spacing: 0.11em;
        color: #344d77;
      }
      .card-art::before,
      .card-art::after {
        content: none;
        position: absolute;
        border: 1px solid #627ba9;
      }
      .art-grid::before {
        width: 6rem;
        height: 6rem;
        right: 2rem;
        top: 2rem;
        border-radius: 0.5rem;
        background:
          repeating-linear-gradient(
            90deg,
            transparent 0 1.8rem,
            #627ba9 1.8rem 1.85rem
          ),
          repeating-linear-gradient(
            0deg,
            transparent 0 1.8rem,
            #627ba9 1.8rem 1.85rem
          );
        transform: rotate(-10deg);
      }
      .art-type {
        background: #f0ead9;
      }
      .art-type::before {
        width: 8rem;
        height: 1rem;
        right: 1.3rem;
        bottom: 3rem;
        background: #bcb099;
        border: 0;
        transform: rotate(-8deg);
        box-shadow: 0 1.5rem 0 -0.25rem #7c765f;
      }
      .art-focus {
        background: #e7efe6;
      }
      .art-focus::before {
        width: 7rem;
        height: 3rem;
        right: 2rem;
        bottom: 1.1rem;
        border: 2px solid #477151;
        outline: 1px dashed #477151;
        outline-offset: 6px;
        border-radius: 1rem;
        transform: rotate(-8deg);
      }
      .art-space {
        background: #f1e8e3;
      }
      .art-space::before {
        width: 3.5rem;
        height: 3.5rem;
        border-radius: 50%;
        background: #a8735e;
        border: 0;
        right: 2rem;
        bottom: 0.8rem;
      }
      .art-space::after {
        width: 5rem;
        height: 5rem;
        border-radius: 50%;
        right: 4.5rem;
        top: 2rem;
        border-color: #a8735e;
      }
      .art-motion {
        background: #ede8f5;
      }
      .art-motion::before {
        width: 4rem;
        height: 4rem;
        border-radius: 50%;
        right: 2rem;
        top: 3rem;
        background: #9884b8;
        border: 0;
        box-shadow:
          -1.5rem 0 0 #c3b7d5,
          -3rem 0 0 #d6cfe2;
      }
      .art-reading {
        background: #e2eeef;
      }
      .art-reading::before {
        width: 6rem;
        height: 6rem;
        background: #fbfcf9;
        right: 2rem;
        top: 2rem;
        transform: rotate(10deg);
        border-color: #698788;
      }
      .art-reading::after {
        width: 4rem;
        height: 3rem;
        border: 0;
        background: repeating-linear-gradient(
          0deg,
          #698788 0 1px,
          transparent 1px 0.65rem
        );
        right: 3rem;
        top: 3rem;
        transform: rotate(10deg);
      }
      .card-body {
        padding: 1.4rem;
        display: flex;
        flex-direction: column;
        flex: 1;
      }
      .card h2 {
        font-size: 1.18rem;
        line-height: 1.4;
        letter-spacing: -0.025em;
        overflow-wrap: anywhere;
      }
      .card p {
        color: var(--muted);
        font-size: 0.86rem;
        margin: 0.75rem 0 1.4rem;
      }
      @media (max-width: 680px) {
        .intro-heading,
        .intro-heading {
          gap: 1.25rem;
        }
        .masthead {
          margin-bottom: 2rem;
        }
      }

      .card-art::before,
      .art-space::after,
      .art-reading::after {
        content: '';
      }
      .card-details {
        margin-top: auto;
        border-top: 1px solid #e0e3e6;
      }
      .card-details summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        min-height: 44px;
        padding-top: 0.75rem;
        list-style: none;
        cursor: pointer;
        color: var(--blue);
        font-size: 0.78rem;
        font-weight: 700;
      }
      .card-details summary::-webkit-details-marker {
        display: none;
      }
      .card-details summary:hover {
        text-decoration: underline;
        text-underline-offset: 0.2em;
      }
      .disclosure-icon {
        flex: 0 0 1rem;
        width: 1rem;
        height: 1rem;
        position: relative;
      }
      .disclosure-icon::before,
      .disclosure-icon::after {
        content: '';
        position: absolute;
        width: 0.7rem;
        height: 1px;
        background: currentColor;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
      .disclosure-icon::after {
        transform: translate(-50%, -50%) rotate(90deg);
      }
      .card-details[open] .disclosure-icon::after {
        display: none;
      }
      .card-note p {
        margin: 1rem 0 0;
      }
      .card-note code {
        font-size: 0.85em;
        overflow-wrap: anywhere;
      }
    </style>
  </head>
  <body>
    <main id="main">
      <header class="masthead">
        <p class="eyebrow">MRHTML / Design notebook</p>
        <span class="edition">Six ideas.<br />Room to grow.</span>
      </header>
      <div class="intro-heading">
        <h1>Good patterns.<br />Any screen.</h1>
        <p class="intro">
          A small collection of useful interface ideas. This grid finds its own
          column count, leaving every card enough room to breathe.
        </p>
      </div>
      <section class="card-grid" aria-label="Design pattern cards">
        <article class="card">
          <div class="card-art art-grid" aria-hidden="true">
            <span class="art-label">01 / Structure</span>
          </div>
          <div class="card-body">
            <h2>A flexible grid that fits the space you actually have</h2>
            <p>
              Let the available width decide how many columns belong in the row.
            </p>
            <details class="card-details">
              <summary>
                Read the layout note<span
                  class="disclosure-icon"
                  aria-hidden="true"
                ></span>
              </summary>
              <div class="card-note">
                <p>
                  The grid uses
                  <code>repeat(auto-fit, minmax(min(100%, 16rem), 1fr))</code>.
                  The inner minimum prevents a card from becoming wider than its
                  container on narrow screens. Cards share the remaining space.
                </p>
              </div>
            </details>
          </div>
        </article>
        <article class="card">
          <div class="card-art art-type" aria-hidden="true">
            <span class="art-label">02 / Typography</span>
          </div>
          <div class="card-body">
            <h2>Headings that welcome a few extra words</h2>
            <p>
              Give real content room to wrap without forcing every title onto
              two lines.
            </p>
            <details class="card-details">
              <summary>
                Read the content note<span
                  class="disclosure-icon"
                  aria-hidden="true"
                ></span>
              </summary>
              <div class="card-note">
                <p>
                  These cards have no fixed title height or line clamp. Short
                  and long headings remain visible, while flexible card bodies
                  keep the reading controls aligned within each row.
                </p>
              </div>
            </details>
          </div>
        </article>
        <article class="card">
          <div class="card-art art-focus" aria-hidden="true">
            <span class="art-label">03 / Interaction</span>
          </div>
          <div class="card-body">
            <h2>A clear path for the keyboard</h2>
            <p>
              One native reading control per card keeps the journey predictable
              and easy to follow.
            </p>
            <details class="card-details">
              <summary>
                Read the keyboard note<span
                  class="disclosure-icon"
                  aria-hidden="true"
                ></span>
              </summary>
              <div class="card-note">
                <p>
                  Use Tab to move between summaries, then Enter or Space to open
                  a note. The grid does not visually reorder cards, so the
                  keyboard path follows the reading order. Native details need
                  no custom role or keyboard handler.
                </p>
              </div>
            </details>
          </div>
        </article>
        <article class="card">
          <div class="card-art art-space" aria-hidden="true">
            <span class="art-label">04 / Rhythm</span>
          </div>
          <div class="card-body">
            <h2>Space that does a little of the explaining</h2>
            <p>
              Consistent gaps and a quiet divider help related ideas stay
              together.
            </p>
            <details class="card-details">
              <summary>
                Read the spacing note<span
                  class="disclosure-icon"
                  aria-hidden="true"
                ></span>
              </summary>
              <div class="card-note">
                <p>
                  A repeated card structure creates rhythm. The title and
                  excerpt stay close together; a divider separates the reading
                  control. Spacing remains flexible as text wraps, including
                  when you increase the text size.
                </p>
              </div>
            </details>
          </div>
        </article>
        <article class="card">
          <div class="card-art art-motion" aria-hidden="true">
            <span class="art-label">05 / Restraint</span>
          </div>
          <div class="card-body">
            <h2>Useful movement, with a quieter option</h2>
            <p>
              A design can communicate its structure without making anything
              move.
            </p>
            <details class="card-details">
              <summary>
                Read the motion note<span
                  class="disclosure-icon"
                  aria-hidden="true"
                ></span>
              </summary>
              <div class="card-note">
                <p>
                  This example has no animation and needs no JavaScript. Its
                  reduced-motion rule also protects the page if you add movement
                  later. Any added motion should respect that preference.
                </p>
              </div>
            </details>
          </div>
        </article>
        <article class="card">
          <div class="card-art art-reading" aria-hidden="true">
            <span class="art-label">06 / Reading</span>
          </div>
          <div class="card-body">
            <h2>A comfortable place for the longer explanation</h2>
            <p>
              Keep a clear excerpt in the card and the full explanation close at
              hand.
            </p>
            <details class="card-details">
              <summary>
                Read the reading note<span
                  class="disclosure-icon"
                  aria-hidden="true"
                ></span>
              </summary>
              <div class="card-note">
                <p>
                  Each card contains a useful local note. Opening a summary
                  reveals it in place, without navigating away from an embedded
                  preview. Replace the sample writing with your own resource
                  descriptions and explanations.
                </p>
              </div>
            </details>
          </div>
        </article>
      </section>
      <footer class="footer-note">
        An original MRHTML example. Six cards, one responsive CSS grid, no
        JavaScript.
      </footer>
    </main>
  </body>
</html>