How can I create a responsive grid layout using only HTML and CSS?
Asked on Oct 16, 2025
Answer
To create a responsive grid layout using only HTML and CSS, you can utilize the CSS Grid Layout module. This allows you to define a grid container and specify the size and position of its child elements.
<!-- BEGIN COPY / PASTE -->
<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>
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
gap: 10px;
}
.grid-item {
background-color: #ccc;
padding: 20px;
text-align: center;
}
</style>
<!-- END COPY / PASTE -->Additional Comment:
- The
grid-template-columnsproperty usesrepeatwithauto-fillto automatically adjust the number of columns based on available space. minmax(100px, 1fr)ensures each column is at least 100px wide but can grow to fill the available space.- The
gapproperty adds spacing between grid items, enhancing readability and aesthetics.
✅ Answered with HTML best practices.
Recommended Links: