Ask any question about HTML here... and get an instant response.
How can I create a responsive grid layout using only HTML and CSS?
Asked on Dec 05, 2025
Answer
To create a responsive grid layout using only HTML and CSS, you can use the CSS Grid Layout module. This allows you to define a grid structure and place items within it, adjusting automatically to different screen sizes.
<!-- 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-columnsproperty defines the number of columns and their size. - The
repeat(auto-fill, minmax(100px, 1fr))function creates as many columns as will fit in the container, each at least 100px wide. - The
gapproperty adds spacing between grid items. - Using
1frensures columns take up remaining space equally.
✅ Answered with HTML best practices.
Recommended Links:
