Yogesh Chauhan's Blog

Responsive Masonry Grid using CSS columns Property

in CSS on July 20, 2021

There are different ways to make grid using CSS in-built properties. You can use Flex or Grid or just block with columns! Let’s use the last option to do that.

Step 1: HTML

Just a simple container and images using picsum API call. Any random images with manually typing random width and height. We’ll adjust the height and width using CSS later on.

Step 2: CSS

This few lines of SCSS is what does the trick!

You can change the number of columns from 4 to 5 or 3 as per your requirements.

.grid-container {
  columns: 4 10rem;
  column-gap: 1rem;
  width: 90%;
  padding: 0 5%;

  .img-container {
    margin-bottom: 1rem;

    img {
      width: 100%;
      border-radius: 1rem;

Checkout the demo:

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to detect the Blog Page in WordPress?WordPressUse eq() method in jQueryjQueryPHP __construct() functionPHPHow to add and remove list items using JavaScript?JavaScriptHow to Access a Global Variable From Inside a Function in PHP?PHPHow to Create a Copy of a Table in SQL and MySQL?SQL/MySQLWordPress Plugin: Things to knowWordPressHow to get query string values in JavaScript? (URL Manipulation using URLSearchParams)JavaScriptHow does while loop work in SCSS?SCSSAND, OR and NOT boolean operators in Envision BasicEnvision BasicWhat’s the difference between a Framework and a Library?MiscellaneousIs monitoring an employee’s work on a computer a desirable or undesirable activity?Miscellaneous