Component Library

← Back to gallery

Project Card Grid in HTML, CSS and vanilla JS

A copy-paste Project Card Grid in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Layout · Tags: card, split, layout

Live preview

Source (copy-ready)

<section class="example-project-card-grid" data-dcl-layout="split" data-dcl-scheme="light" aria-labelledby="example-project-card-grid-title"><header><h2 id="example-project-card-grid-title">Project Card Grid</h2></header><div class="parts"><article><h3>Directory</h3><p>An index of the teams using the library.</p></article><article><h3>Sandbox</h3><p>A space for trying UI patterns.</p></article><article><h3>Device lab</h3><p>A record of supported devices.</p></article></div>
<script>
(() => {
  const root = document.currentScript.closest(".example-project-card-grid");
  const instance = Array.from(document.getElementsByClassName("example-project-card-grid")).indexOf(root);
  if (instance > 0) {
    const references = ["id", "aria-labelledby", "aria-controls", "aria-describedby", "for", "name"];
    for (const element of [root, ...root.querySelectorAll("*")]) {
      for (const attr of references) {
        if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr) + "--" + instance);
      }
      const href = element.getAttribute("href");
      if (href && href.startsWith("#")) element.setAttribute("href", href + "--" + instance);
    }
  }
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const apply = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", apply);
  apply();

})();
</script></section>
<style>

.example-project-card-grid { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-project-card-grid a { color: #005c62; }
.example-project-card-grid button, .example-project-card-grid summary, .example-project-card-grid input, .example-project-card-grid select {
  color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-project-card-grid button:hover, .example-project-card-grid summary:hover, .example-project-card-grid button[aria-selected="true"] {
  color: #ffffff; background-color: #00535a;
}
.example-project-card-grid dialog { color: #11292f; background-color: #ffffff; }
.example-project-card-grid [data-note] { color: #11292f; background-color: #e4edef; }
.example-project-card-grid :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }


.example-project-card-grid[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-project-card-grid[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-project-card-grid[data-dcl-scheme="dark"] button, .example-project-card-grid[data-dcl-scheme="dark"] summary, .example-project-card-grid[data-dcl-scheme="dark"] input, .example-project-card-grid[data-dcl-scheme="dark"] select {
  color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-project-card-grid[data-dcl-scheme="dark"] button:hover, .example-project-card-grid[data-dcl-scheme="dark"] summary:hover, .example-project-card-grid[data-dcl-scheme="dark"] button[aria-selected="true"] {
  color: #11292f; background-color: #8fe1da;
}
.example-project-card-grid[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-project-card-grid[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-project-card-grid[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }

.example-project-card-grid, .example-project-card-grid * { box-sizing: border-box; }
.example-project-card-grid { font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-project-card-grid h2, .example-project-card-grid h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-project-card-grid p { margin-block: 0.5rem; }
.example-project-card-grid ul { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-project-card-grid article, .example-project-card-grid details, .example-project-card-grid [data-note] { border: 1px solid; border-radius: 0.375rem; padding: 0.75rem; }
.example-project-card-grid button, .example-project-card-grid summary, .example-project-card-grid input, .example-project-card-grid select {
  min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-project-card-grid button, .example-project-card-grid summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-project-card-grid button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-project-card-grid input { display: block; inline-size: 100%; }
.example-project-card-grid dialog { max-inline-size: min(32rem, 90vw); border-radius: 0.75rem; padding: 1rem; }
.example-project-card-grid th, .example-project-card-grid td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-project-card-grid table { border-collapse: collapse; inline-size: 100%; }
.example-project-card-grid caption { font-weight: bold; text-align: start; }
.example-project-card-grid dt { font-weight: 600; }
.example-project-card-grid dd { margin: 0 0 0.75rem; }
.example-project-card-grid [hidden] { display: none !important; }
.example-project-card-grid .parts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 1rem; }

@media (max-width: 30rem) {
  .example-project-card-grid[data-dcl-layout="rail"] .parts { grid-template-columns: minmax(0, 1fr); }
  .example-project-card-grid[data-dcl-layout="rail"] .parts > :is(p, ul, article) { grid-column: 1; grid-row: auto; }
  .example-project-card-grid[data-dcl-layout="rail"] .parts > :is(details, nav) { grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) { .example-project-card-grid * { transition: none !important; } }
</style>

When to use

Use this split arrangement when readers benefit from seeing items side by side.

Avoid

Prefer a plain list or table for dense, uniform facts.

Accessibility

Keep heading levels in order and do not depend on the card boundary for meaning.

Was this useful? Send feedback.