Component Library

← Back to gallery

Expandable project cards in HTML, CSS and vanilla JS

A copy-paste Expandable project cards in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Layout · Tags: cards, expandable, details, projects

Live preview

Source (copy-ready)

<section class="dcl-expandable-project-cards" data-dcl-scheme="light" aria-labelledby="dcl-expandable-project-cards-title"><header class="dcl-expandable-project-cards__header"><h2 id="dcl-expandable-project-cards-title">Expandable project cards</h2><p class="dcl-expandable-project-cards__muted">Compact cards reveal supplementary detail only when requested.</p></header><div class="dcl-expandable-project-cards__grid"><article class="dcl-expandable-project-cards__card"><h3>Migration rehearsal</h3><p>Owner: Ari. Freeze window Friday.</p><details><summary>More detail</summary><p class="dcl-expandable-project-cards__muted">Rollback evidence and validation count.</p></details></article><article class="dcl-expandable-project-cards__card"><h3>Billing cleanup</h3><p>Owner: Mina. Review due Tuesday.</p><details><summary>More detail</summary><p class="dcl-expandable-project-cards__muted">Tax-rule exceptions and invoice sample.</p></details></article><article class="dcl-expandable-project-cards__card"><h3>API deprecation</h3><p>Owner: Jules. Notice sent Monday.</p><details><summary>More detail</summary><p class="dcl-expandable-project-cards__muted">Remaining callers and sunset checklist.</p></details></article></div><script>(()=>{const root=document.currentScript.closest(".dcl-expandable-project-cards");if(!root||root.dataset.dclBound)return;root.dataset.dclBound="1";const instance=Array.from(document.getElementsByClassName("dcl-expandable-project-cards")).indexOf(root);if(instance>0){for(const el of [root,...root.querySelectorAll("*")]){for(const attr of ["id","aria-labelledby","aria-controls","aria-describedby","for","name"]){if(el.hasAttribute(attr))el.setAttribute(attr,el.getAttribute(attr)+"--"+instance)}const href=el.getAttribute("href");if(href&&href.startsWith("#"))el.setAttribute("href",href+"--"+instance)}}const preference=matchMedia("(prefers-color-scheme: dark)"),apply=()=>{root.dataset.dclScheme=preference.matches?"dark":"light"};preference.addEventListener("change",apply);apply();const q=(s)=>root.querySelector(s),qa=(s)=>Array.from(root.querySelectorAll(s));})();</script></section>
<style>
.dcl-expandable-project-cards{color:#11292f;background-color:#ffffff;color-scheme:light;font:1rem/1.45 system-ui,sans-serif;padding:.8rem;border:1px solid #697f84;border-radius:.6rem;overflow-wrap:anywhere}
.dcl-expandable-project-cards *{box-sizing:border-box}.dcl-expandable-project-cards h2,.dcl-expandable-project-cards h3{line-height:1.15;margin-block:0 .6rem}.dcl-expandable-project-cards a{color:#005c62}
.dcl-expandable-project-cards button,.dcl-expandable-project-cards input,.dcl-expandable-project-cards select,.dcl-expandable-project-cards textarea,.dcl-expandable-project-cards summary{min-block-size:44px;border:1px solid #697f84;border-radius:.3rem;padding:.4rem .65rem;font:inherit;color:#11292f;background-color:#e4edef}
.dcl-expandable-project-cards input,.dcl-expandable-project-cards select,.dcl-expandable-project-cards textarea{background-color:#ffffff}.dcl-expandable-project-cards input[type="radio"],.dcl-expandable-project-cards input[type="checkbox"]{min-block-size:auto;inline-size:auto}
.dcl-expandable-project-cards button,.dcl-expandable-project-cards summary{cursor:pointer}.dcl-expandable-project-cards button:hover,.dcl-expandable-project-cards summary:hover{color:#ffffff;background-color:#00535a}
.dcl-expandable-project-cards button:focus-visible,.dcl-expandable-project-cards input:focus-visible,.dcl-expandable-project-cards select:focus-visible,.dcl-expandable-project-cards textarea:focus-visible,.dcl-expandable-project-cards summary:focus-visible,.dcl-expandable-project-cards a:focus-visible{outline:3px solid #005c62;outline-offset:2px}
.dcl-expandable-project-cards details{color:#11292f;background-color:#ffffff;border:1px solid #697f84;border-radius:.4rem;margin-block-start:.6rem}.dcl-expandable-project-cards summary{font-weight:650}
.dcl-expandable-project-cards dialog{color:#11292f;background-color:#ffffff;border:1px solid #697f84;border-radius:.6rem;max-inline-size:min(34rem,92vw);padding:1rem}
.dcl-expandable-project-cards table{border-collapse:collapse;inline-size:100%;color:#11292f;background-color:#ffffff}.dcl-expandable-project-cards th,.dcl-expandable-project-cards td{padding:.4rem;text-align:start;border-block-end:1px solid #697f84}.dcl-expandable-project-cards th{color:#11292f;background-color:#e4edef}
.dcl-expandable-project-cards [hidden]{display:none!important}.dcl-expandable-project-cards__muted{color:#405a60}.dcl-expandable-project-cards__panel{color:#405a60;background-color:#ffffff}.dcl-expandable-project-cards__well{color:#11292f;background-color:#e4edef}.dcl-expandable-project-cards__primary,.dcl-expandable-project-cards__badge{color:#ffffff;background-color:#00535a}.dcl-expandable-project-cards__badge{border-radius:999px;padding:.1rem .45rem;font-size:.8rem;font-weight:700}
.dcl-expandable-project-cards[data-dcl-scheme="dark"]{color:#eff8f9;background-color:#142f36;color-scheme:dark;border-color:#839fa5}.dcl-expandable-project-cards[data-dcl-scheme="dark"] a{color:#8fe1da}
.dcl-expandable-project-cards[data-dcl-scheme="dark"] button,.dcl-expandable-project-cards[data-dcl-scheme="dark"] input,.dcl-expandable-project-cards[data-dcl-scheme="dark"] select,.dcl-expandable-project-cards[data-dcl-scheme="dark"] textarea,.dcl-expandable-project-cards[data-dcl-scheme="dark"] summary{color:#eff8f9;background-color:#1c3c44;border-color:#839fa5}
.dcl-expandable-project-cards[data-dcl-scheme="dark"] input,.dcl-expandable-project-cards[data-dcl-scheme="dark"] select,.dcl-expandable-project-cards[data-dcl-scheme="dark"] textarea{background-color:#142f36}.dcl-expandable-project-cards[data-dcl-scheme="dark"] button:hover,.dcl-expandable-project-cards[data-dcl-scheme="dark"] summary:hover{color:#11292f;background-color:#8fe1da}
.dcl-expandable-project-cards[data-dcl-scheme="dark"] button:focus-visible,.dcl-expandable-project-cards[data-dcl-scheme="dark"] input:focus-visible,.dcl-expandable-project-cards[data-dcl-scheme="dark"] select:focus-visible,.dcl-expandable-project-cards[data-dcl-scheme="dark"] textarea:focus-visible,.dcl-expandable-project-cards[data-dcl-scheme="dark"] summary:focus-visible,.dcl-expandable-project-cards[data-dcl-scheme="dark"] a:focus-visible{outline-color:#8fe1da}
.dcl-expandable-project-cards[data-dcl-scheme="dark"] details,.dcl-expandable-project-cards[data-dcl-scheme="dark"] dialog,.dcl-expandable-project-cards[data-dcl-scheme="dark"] table{color:#eff8f9;background-color:#142f36;border-color:#839fa5}.dcl-expandable-project-cards[data-dcl-scheme="dark"] th{color:#eff8f9;background-color:#1c3c44}.dcl-expandable-project-cards[data-dcl-scheme="dark"] th,.dcl-expandable-project-cards[data-dcl-scheme="dark"] td{border-color:#839fa5}
.dcl-expandable-project-cards[data-dcl-scheme="dark"] .dcl-expandable-project-cards__muted{color:#b0c9ce}.dcl-expandable-project-cards[data-dcl-scheme="dark"] .dcl-expandable-project-cards__panel{color:#b0c9ce;background-color:#142f36}.dcl-expandable-project-cards[data-dcl-scheme="dark"] .dcl-expandable-project-cards__well{color:#eff8f9;background-color:#1c3c44}.dcl-expandable-project-cards[data-dcl-scheme="dark"] .dcl-expandable-project-cards__primary,.dcl-expandable-project-cards[data-dcl-scheme="dark"] .dcl-expandable-project-cards__badge{color:#11292f;background-color:#8fe1da}
@media (prefers-reduced-motion:reduce){.dcl-expandable-project-cards *{transition:none!important;animation:none!important}}
.dcl-expandable-project-cards__grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr));gap:.75rem}.dcl-expandable-project-cards__card{border:1px solid #697f84;border-radius:.5rem;padding:.75rem}.dcl-expandable-project-cards details{margin-block-end:0}</style>

When to use

Use when scan-first cards occasionally need one supporting paragraph. Keep hidden detail supplementary rather than required to understand the card.

Avoid

Do not hide the card title or primary action inside the expansion; essential content must remain visible.

Accessibility

Expansion uses native details and summary controls inside each card, so keyboard operation does not depend on custom JavaScript. Card text is #405a60 on #ffffff (7.37:1) with headings at #11292f on #ffffff (15.19:1); dark equivalents are #b0c9ce on #142f36 (8.12:1) and #eff8f9 on #142f36 (13.07:1). Interactive controls use visible focus outlines.

Was this useful? Send feedback.