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 Mar 19, 2026
Answer
Creating a responsive grid layout with CSS Grid is straightforward and powerful. CSS Grid allows you to define grid areas and adjust them based on screen size using media queries.
<!-- BEGIN COPY / PASTE -->
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
gap: 10px;
}
.grid-item {
background-color: #f0f0f0;
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 class="grid-item">5</div>
<div class="grid-item">6</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The `grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));` rule creates a responsive grid where each column is at least 100px wide and grows to fill available space.
- The `gap` property adds spacing between grid items, enhancing readability and aesthetics.
- Use media queries to adjust the `minmax` values for different screen sizes if more control is needed.
- CSS Grid is supported in all modern browsers, making it a reliable choice for responsive design.
Recommended Links:
