Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a responsive grid layout that adjusts to different screen sizes using CSS Grid?
Asked on Feb 03, 2026
Answer
Creating a responsive grid layout using CSS Grid involves defining grid areas and using media queries to adjust the layout for different screen sizes. Here's a basic example to get you started.
<!-- BEGIN COPY / PASTE -->
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.grid-item {
background-color: #f0f0f0;
padding: 20px;
text-align: center;
}
@media (max-width: 768px) {
.grid-container {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 480px) {
.grid-container {
grid-template-columns: 1fr;
}
}
</style>
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The grid layout starts with three equal columns using "repeat(3, 1fr)".
- Media queries adjust the number of columns based on the screen width.
- At 768px or less, the layout changes to two columns.
- At 480px or less, the layout switches to a single column.
- Use "gap" to control spacing between grid items.
Recommended Links:
