Ask any question about HTML here... and get an instant response.
How can I create a responsive image gallery using HTML only?
Asked on Nov 01, 2025
Answer
To create a responsive image gallery using HTML only, you can use a combination of the
<figure> and <img> elements along with CSS Flexbox for layout. This setup allows images to adjust their size and layout based on the screen size.
<!-- BEGIN COPY / PASTE -->
<style>
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.gallery figure {
flex: 1 1 calc(33.333% - 10px);
margin: 0;
}
.gallery img {
width: 100%;
height: auto;
display: block;
}
</style>
<div class="gallery">
<figure>
<img src="image1.jpg" alt="Description of Image 1">
</figure>
<figure>
<img src="image2.jpg" alt="Description of Image 2">
</figure>
<figure>
<img src="image3.jpg" alt="Description of Image 3">
</figure>
<!-- Add more images as needed -->
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The
<figure>element is used to group the image and its caption, though captions are optional here. - Flexbox properties like
flex-wrapandflexhelp in making the gallery responsive. - The
calc()function is used to ensure the images fit well with the gap included.
✅ Answered with HTML best practices.
Recommended Links:
