VOOZH about

URL: https://www.geeksforgeeks.org/css/css-image-gallery/

⇱ CSS Image Gallery - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS Image Gallery

Last Updated : 4 Jul, 2024

Creating a responsive image gallery is a great way to showcase a collection of pictures on your website. In this article, we'll walk you through the steps to build a responsive image gallery using HTML and CSS. This guide will help you create a beautiful gallery that looks great on all devices.

Step 1: Creating a Basic Gallery Structure

First, let's set up the basic structure of our gallery. Each gallery will contain a number of div sections. Each div section will contain an image and its description.

Here's an example of the HTML structure:

Step 2: Styling the Gallery with CSS

Next, we need to style our gallery using CSS to make it look appealing and responsive.

Styling the Gallery Container

To style the gallery container, we will set the display property to flex. This means elements within the gallery container will have a flex context. We will also set the flex-flow property to row wrap, which sets the flex-direction and flex-wrap style.

Styling the Box

Now, let's style each box in the gallery. We'll set the flex-basis to 20%, ensuring that each box takes up 20% of the container's width. We'll also add padding, margin, and a shadow effect for better look.

Step 3: Making the Gallery Responsive

To make the gallery responsive, we will use CSS media queries. This will ensure that the gallery looks great on devices with different screen sizes.

Example Media Query

Here's an example of a media query that adjusts the layout for screens with a maximum width of 300px:

Example Output

Here's what the final output might look like:

Output:

👁 image gallery

We've shown you how to create a responsive image gallery using HTML and CSS. By following these steps, you can build a gallery that looks great on any device. Don't forget to customize the gallery with your images and styles to make it unique.

Comment
Article Tags:
Article Tags: