The grid style you need is called 'Masonry Layout'. You will get many ready to use cdn on the web. Just embed a cdn in the script tag inside the head tag. And it would do the magic.
I am providing a sample code for you down here.
.image {
width: 100%;
object-fit: cover;
}
#image1{
height: 550px;
}
#image2{
height: 350px;
}
#image3{
height: 450px;
}
#image4{
height: 550px;
}
#image5{
height: 250px;
}
#image6{
height: 450px;
}
#image7{
height: 450px;
}
#image8{
height: 450px;
}
#image9{
height: 550px;
}
#image10{
height: 250px;
}
#image11{
height: 250px;
}
#image12{
height: 250px;
}
@media only screen and (max-width:992px) {
.image{
height:400px;
}
}
@media only screen and (max-width:768px) {
.image{
height:300px;
}
}
@media only screen and (max-width:576px) {
#image1{
height:250px;
}
#image2{
height:250px;
}
#image3{
height:250px;
}
#image4{
height:250px;
}
#image5{
height:250px;
}
#image6{
height:250px;
}
}
<!doctype html>
<html>
<head>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!--Masonry Layout cdn-->
<script defer src="https://cdn.jsdelivr.net/npm/masonry-layout@4.2.2/dist/masonry.pkgd.min.js"
integrity="sha384-GNFwBvfVxBkLMJpYMOABq3c+d3KnQxudP/mGPkzpZSTYykLBNsZEnG2D9G/X/+7D" crossorigin="anonymous"
async></script>
</head>
<body>
<section >
<div class="container">
<div class="row g-3" data-masonry='{"percentPosition": true }'>
<div class="col-lg-4 col-md-6 col-12 ">
<img class="image" id="image1" src="https://i.ibb.co/YNvbbMC/0V5A0971.jpg">
</div>
<div class="col-lg-4 col-md-6 col-12">
<img class="image" id="image2" src="https://i.ibb.co/YpZ3NBH/0V5A0975.jpg">
</div>
<div class="col-lg-4 col-md-6 col-12">
<img class="image" id="image3" src="https://i.ibb.co/pxVtdR9/0V5A0980.jpg">
</div>
<div class="col-lg-4 col-md-6 col-12">
<img class="image" id="image4" src="https://i.ibb.co/CWTXksK/0V5A2619.jpg" >
</div>
<div class="col-lg-4 col-md-6 col-12">
<img class="image" id="image5" src="https://i.ibb.co/LJdmcdc/0V5A2620.jpg">
</div>
<div class="col-lg-4 col-md-6 col-12">
<img class="image" id="image6" src="https://i.ibb.co/XxMVkDX/0V5A2621.jpg">
</div>
</div>
</div>
</section>
</body>
</html>
Click on 'Full page' and adjust the window to see it's responsive behaviour.
Let me explain the code.
Masonry cdn is embedded inside the head. I have used Bootstrap here. It would work even with regular CSS. But Bootstrap makes life easy. Class 'image' is common to all the images and each one is having its own id.
Applying width 100% and object-fit=cover to all the images so that they don't overflow. Next, I have mentioned the default heights of images followed by how much should their height be as the window width changes.