24 CSS Grid Layouts

Pinterest Masonry

Masonry-style brick layout using `grid-template-rows: masonry` (with `grid-auto-flow: dense` fallback). Cards of varying heights pack tightly without gaps — the Pinterest pattern, native CSS.

Pure CSS MIT licensed
Live Demo Open in tab
Open in playground

The code

<div class="gl-mas">
  <article class="gl-mas-c1"><strong>Card 1</strong><em>row 1 · h: 1.5×</em></article>
  <article class="gl-mas-c2"><strong>Card 2</strong><em>row 1 · h: 1×</em></article>
  <article class="gl-mas-c3"><strong>Card 3</strong><em>row 2 · h: 2×</em></article>
  <article class="gl-mas-c4"><strong>Card 4</strong><em>row 2 · h: 1×</em></article>
  <article class="gl-mas-c5"><strong>Card 5</strong><em>row 3 · h: 1.5×</em></article>
  <article class="gl-mas-c6"><strong>Card 6</strong><em>row 3 · h: 1×</em></article>
  <article class="gl-mas-c7"><strong>Card 7</strong><em>row 4 · h: 1×</em></article>
</div>
.gl-mas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  grid-auto-flow: dense;
  grid-auto-rows: 60px;
  gap: 12px;
  width: 100%;
  min-height: 480px;
  padding: 22px;
  background:
    radial-gradient(50% 80% at 50% 0%, rgba(244,63,94,0.14), transparent 60%),
    #1a060c;
  font-family: 'Inter', system-ui, sans-serif;
  color: #ffe4e6;
  box-sizing: border-box;
  align-content: start;
}
.gl-mas > article {
  background: linear-gradient(160deg, rgba(244,63,94,0.16), rgba(190,18,60,0.06));
  border: 1px solid rgba(244,63,94,0.28);
  border-radius: 14px;
  padding: 16px;
  display: flex; flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}
.gl-mas > article strong { font-size: 14px; font-weight: 700; color: #fff; }
.gl-mas > article em {
  font-style: normal;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: #fb7185;
  align-self: flex-start;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(244,63,94,0.12);
}
.gl-mas-c1 { grid-row: span 3; background: linear-gradient(180deg, #f43f5e, #e11d48) !important; border: 0 !important; }
.gl-mas-c1 em { color: #fff; background: rgba(26,6,12,0.3); }
.gl-mas-c2 { grid-row: span 2; }
.gl-mas-c3 { grid-row: span 4; background: linear-gradient(180deg, rgba(244,63,94,0.32), rgba(190,18,60,0.14)); }
.gl-mas-c4 { grid-row: span 2; }
.gl-mas-c5 { grid-row: span 3; }
.gl-mas-c6 { grid-row: span 2; background: linear-gradient(180deg, #fb7185, #f43f5e) !important; border: 0 !important; }
.gl-mas-c6 em { color: #fff; background: rgba(26,6,12,0.3); }
.gl-mas-c7 { grid-row: span 2; }

Search CodeFronts

Loading…