dots Created with Sketch.
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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
4 different Ways to Get JavaScript OutputJavaScriptContent Blocks in SCSS (Sass)SCSSWhat is Host Hardening and What are some Important Hardening Steps?MiscellaneousHow to make HTML form interactive and using CSS?CSSLearn to Implement Estimated Reading Time using PHP Part 2: Final Implementation with Source CodePHPWhat is HTMLUnknownElement?HTMLWordPress: How to find all posts from a custom post type with specific custom field?WordPressGap in Flex?CSS2 Ways we can create an Array in JavaScriptJavaScriptSELF JOIN in PostgresPostgresIntroduction to components and templates Part 2: Templates and viewsAngularNATURAL JOIN in PostgresPostgres