Skip to content
Omni Academy
Search courses and lessons
Search
Courses
Backend Development
9
Databases
1
Frontend Development
5
Data Science
5
All courses →
Playground
HTML & CSS
JavaScript
TypeScript
Python
PHP
Ruby
Light
Dark
Auto
Sign in
Get started
All
Backend Development
Databases
Frontend Development
Data Science
Playground
Blog
HTML
JS
TS
PY
PHP
RB
← Courses
📄
A CSS grid layout
Run as I type
Reset
▶
Run
Ctrl
↵
HTML
HTML & CSS source code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Card grid</title> <style> *, *::before, *::after { box-sizing: border-box; } body { font: 16px/1.6 system-ui, sans-serif; margin: 0; padding: clamp(1rem, 4vw, 2rem); background: #fbfbfd; color: #16181d; } h1 { font-size: clamp(1.5rem, 1rem + 2.5vw, 2.25rem); margin: 0 0 1.25rem; } /* No media query. auto-fit fits as many columns as will hold 14rem, and min() stops the track overflowing a narrow box. */ .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr)); gap: 1rem; list-style: none; margin: 0; padding: 0; } .card { display: grid; grid-template-rows: auto 1fr auto; gap: .4rem; background: #fff; border: 1px solid #e3e5ea; border-radius: 10px; padding: 1rem; } .card h2 { margin: 0; font-size: 1rem; } .card p { margin: 0; color: #5c626e; font-size: .925rem; } .card .meta { color: #868c99; font-size: .8rem; } </style> </head> <body> <h1>Drag the window edge</h1> <ul class="cards"> <li class="card"> <h2>auto-fit</h2> <p>Fits as many columns as will hold the minimum.</p> <span class="meta">grid-template-columns</span> </li> <li class="card"> <h2>minmax</h2> <p>At least 14rem, at most one fair share of what is left.</p> <span class="meta">track sizing</span> </li> <li class="card"> <h2>1fr rows</h2> <p>The meta line sits at the bottom however long this text gets.</p> <span class="meta">grid-template-rows</span> </li> </ul> </body> </html>
Output
Rendered by your browser