CSS Grid is a powerful two-dimensional layout system that enables easy design of both rows and columns simultaneously.
To enable grid layout:
.container {
display: grid;
}
grid-template-columns)Defines the number of columns and their width:
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr; /* Three equal columns */
}
✅ Units: fr (fractional unit), px, %, em, etc.
grid-template-rows)Defines row height:
.container {
display: grid;
grid-template-rows: 100px 200px; /* Two rows with different heights */
}
To set spacing between grid items: