Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a responsive grid layout using CSS Grid?
Asked on Apr 06, 2026
Answer
Creating a responsive grid layout with CSS Grid involves defining grid areas that adjust based on the screen size. CSS Grid provides a powerful way to create flexible and responsive layouts.
<!-- BEGIN COPY / PASTE -->
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
gap: 10px;
}
.grid-item {
background-color: #ccc;
padding: 20px;
text-align: center;
}
</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-template-columns" property uses "repeat(auto-fit, minmax(100px, 1fr))" to create a responsive grid that adapts to the container size.
- "auto-fit" automatically adjusts the number of columns based on the available space.
- "minmax(100px, 1fr)" ensures each grid item is at least 100px wide but can grow to fill the available space equally.
- Use the "gap" property to control the spacing between grid items.
Recommended Links:
