Ask any question about HTML here... and get an instant response.
How can I create a responsive image gallery using HTML?
Asked on Nov 19, 2025
Answer
To create a responsive image gallery using HTML, you can use a combination of the
<figure> and <img> elements along with CSS Flexbox or Grid for layout. This ensures that the images adjust to different screen sizes.
<!-- BEGIN COPY / PASTE -->
<div class="gallery">
<figure>
<img src="image1.jpg" alt="Description of image 1">
<figcaption>Image 1</figcaption>
</figure>
<figure>
<img src="image2.jpg" alt="Description of image 2">
<figcaption>Image 2</figcaption>
</figure>
<figure>
<img src="image3.jpg" alt="Description of image 3">
<figcaption>Image 3</figcaption>
</figure>
</div>
<style>
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
figure {
flex: 1 1 calc(33.333% - 10px);
box-sizing: border-box;
}
img {
width: 100%;
height: auto;
}
</style>
<!-- END COPY / PASTE -->Additional Comment:
- The
<figure>element is used to group the image and its caption. - Flexbox is used to create a responsive layout that adjusts to different screen sizes.
- The
flex-wrap: wrap;property ensures that images wrap onto new lines as needed. - Using
calc()in theflexproperty allows for dynamic sizing with a consistent gap.
✅ Answered with HTML best practices.
Recommended Links:
