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 03, 2026
Answer
Creating a responsive grid layout with CSS Grid is straightforward and allows you to define flexible layouts that adapt to different screen sizes. Here's a simple example to get you started.
<!-- BEGIN COPY / PASTE -->
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 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>
<!-- END COPY / PASTE -->Additional Comment:
- The "grid-template-columns" property uses "repeat(auto-fill, minmax(150px, 1fr))" to create a responsive layout where each column is at least 150px wide and can grow to fill available space.
- The "gap" property adds spacing between grid items, enhancing visual separation.
- This layout automatically adjusts the number of columns based on the container's width, making it responsive.
- Ensure your grid container is within a responsive parent element (like a flexible width div) for best results.
Recommended Links:
