Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a responsive grid layout without using media queries?
Asked on Mar 18, 2026
Answer
Creating a responsive grid layout without media queries can be efficiently achieved using CSS Grid's auto-fit and auto-fill properties. These properties allow the grid to adapt to the available space by automatically adjusting the number of columns.
<!-- BEGIN COPY / PASTE -->
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 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 class="grid-item">5</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The "auto-fit" keyword in "grid-template-columns" allows the grid to fill the row with as many columns as will fit, adjusting automatically.
- "minmax(150px, 1fr)" sets a minimum column width of 150px, while "1fr" allows the columns to expand and fill the available space.
- This approach ensures that the grid is responsive and adapts to different screen sizes without needing media queries.
- Adjust the "minmax" values to control the minimum size and flexibility of the grid items.
Recommended Links:
