Responsive Image Gallery




In Bootstrap 5.3, an image gallery can be easily created using the built-in components and classes provided by Bootstrap. Here's an explanation of how you can create an image gallery in Bootstrap 5.3.

  • Grid System: Bootstrap's grid system allows you to create a responsive layout for your image gallery. You can use the "row" and "col" classes to create a grid structure and define the number of columns you want in each row.
  • Card Component: Bootstrap's "card" component is useful for displaying images in a gallery format. You can use the "card" class to create a container for each image in your gallery. Inside the card, you can include the image itself, along with any additional content such as captions or descriptions.
  • Image Thumbnails: To display the images as thumbnails, you can use the "img-thumbnail" class provided by Bootstrap. This class adds a small border and padding to the image, making it visually distinct from the surrounding elements.
  • Modal: Bootstrap's modal component can be used to display a larger version of an image when clicked. By wrapping the image inside a modal container and adding the necessary attributes and classes, you can create a modal that opens with a larger view of the image.
  • Carousel: If you want to create a slideshow-like experience for your image gallery, you can utilize Bootstrap's carousel component. The carousel allows you to display multiple images in a rotating fashion, with options for navigation and autoplay.

By combining these components and classes, you can create a visually appealing and interactive image gallery in Bootstrap 5.3. Remember to refer to the official Bootstrap documentation for detailed information on each component and its usage.

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Image Gallery</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/base.css" />
  </head>
  <body>
    <div class="container mt-4">
      <h4 class="text-primary mb-4">Responsive Image Gallery</h4>
      <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-2 g-md-3 g-lg-4">
        <div class="col">
          <img class="img-fluid img-thumbnail" src="images/01.jpg" alt="flowers" />
        </div>
        <div class="col">
          <img class="img-fluid img-thumbnail" src="images/02.jpg" alt="flowers" />
        </div>
        <div class="col">
          <img class="img-fluid img-thumbnail" src="images/03.jpg" alt="flowers" />
        </div>
        <div class="col">
          <img class="img-fluid img-thumbnail" src="images/04.jpg" alt="flowers" />
        </div>
        <div class="col">
          <img class="img-fluid img-thumbnail" src="images/05.jpg" alt="flowers" />
        </div>
        <div class="col">
          <img class="img-fluid img-thumbnail" src="images/06.jpg" alt="flowers" />
        </div>
      </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
  </body>
</html>
Live Preview