Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a responsive grid layout with CSS Grid that adapts to different screen sizes?
Asked on Feb 16, 2026
Answer
Creating a responsive grid layout with CSS Grid involves defining grid areas that adjust based on screen size using media queries. This allows your layout to adapt seamlessly to different devices.
<!-- BEGIN COPY / PASTE -->
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
}
.grid-item {
background-color: #f2f2f2;
padding: 20px;
text-align: center;
}
@media (max-width: 600px) {
.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>
<!-- END COPY / PASTE -->Additional Comment:
- The grid uses "auto-fill" and "minmax" to create flexible columns that adapt to the container's width.
- The media query changes the grid to a single column layout on screens smaller than 600px.
- Adjust "minmax(200px, 1fr)" to change the minimum column width.
- Use "gap" to control spacing between grid items.
Recommended Links:
