content logo

Bootstrap Grids:

Bootstrap 5 Masonry Gallery with Image Defer and Images Loaded

You probably have seen websites with many images. As you know, pictures are so important on all websites and you have to care about them. If you own a website, it is better to use some grids to mention all images regularly. In this post, you can see the Bootstrap 5 Masonry Gallery with Image Defer and Images Loaded with an eye-catching design. This Bootstrap Grids Code helps you to organize all pictures of your website beautifully. So, you can use these Pure CSS Grids to regulate the page of your website.

By looking at this preview of these HTML Grids with Images, you realize the beauty of this code. The following Gallery Image Code has a white background with several photos. Some of these images are small and others are large. Additionally, these images are rectangles and look like the gallery of the phones. You can see different images on this post in the mountains, nature, and streets. It is worth noting that all images are customizable and you can change them easily. These Masonry Gallery Grids are available in this post and you can add your favorite images to your website with their help.

 

#

Bootstrap Grids Code

#

Pure CSS Grids

#

HTML Grids with Images

#

Gallery Image Code

#

Masonry Gallery Grids

<!-- This script got from frontendfreecode.com -->
<div class="container">
    <div class="row gy-4 masonry">
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1600/900"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/900/900" class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1600/900"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1600/900"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/900/1600"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/400/700"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1024/768"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/768/1024"  class="img-fluid">
        </div>
    </div>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
window.onload = function () {
    var imgDefer = document.getElementsByTagName("img");
    for (var i = 0; i < imgDefer.length; i++) {
        if (imgDefer[i].getAttribute("data-src")) {
            imgDefer[i].setAttribute("src", imgDefer[i].getAttribute("data-src"));
        }
    }
    var $container = $(".masonry");
    $container.imagesLoaded(function () {
        $container.masonry({
            percentPosition: true
        });
    });
};
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js'></script>
<script src='http://frontendfreecode.com/codes/files/masonry.pkgd.min.js'></script>
<script src='http://frontendfreecode.com/codes/files/imagesloaded.pkgd.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js'></script>
<script src='http://frontendfreecode.com/codes/files/masonry.pkgd.min.js'></script>
<script src='http://frontendfreecode.com/codes/files/imagesloaded.pkgd.min.js'></script>
</head>
<body>
<div class="container">
    <div class="row gy-4 masonry">
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1600/900"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/900/900" class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1600/900"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1600/900"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/900/1600"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/400/700"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/1024/768"  class="img-fluid">
        </div>
        <div class="col-lg-3 col-md-4 col-6">
            <img src="https://picsum.photos/768/1024"  class="img-fluid">
        </div>
    </div>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
window.onload = function () {
    var imgDefer = document.getElementsByTagName("img");
    for (var i = 0; i < imgDefer.length; i++) {
        if (imgDefer[i].getAttribute("data-src")) {
            imgDefer[i].setAttribute("src", imgDefer[i].getAttribute("data-src"));
        }
    }
    var $container = $(".masonry");
    $container.imagesLoaded(function () {
        $container.masonry({
            percentPosition: true
        });
    });
};
</script>

</body>
</html>
Preview