Grid Basics
Set display: grid and define columns with grid-template-columns. The unit fr means a fraction of the free space. grid-template-rows defines rows, and gap sets the spacing.
Grid is perfect for page layouts and card galleries because it controls rows and columns at the same time.
Example
<style>
.grid {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 10px;
}
.grid div { background: #bbf7d0; padding: 20px; text-align: center; }
</style>
<div class="grid">
<div>1fr</div><div>2fr</div><div>1fr</div>
<div>A</div><div>B</div><div>C</div>
</div>Exercise
Create three equal columns.
.grid { display: grid; grid-template-columns: repeat(3, 1); }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.