How To Create a Masonry Layout With Divi’s Gallery Module

Last modified May 25, 2023
Difficulty Beginner
Language CSS
Create a Masonry Layout With Divi's Gallery Module

Creating a masonry gallery with the Divi theme using only the built-in features and native Divi modules is a highly requested feature among Divi users. However, the Divi theme alone cannot achieve a masonry gallery layout without the use of additional plugins or custom code.  In this tutorial, we will explore one method of implementing a masonry layout for the Divi theme that involves implementing custom CSS Divi code snippet. Although it requires custom coding, it’s as simple as copying and pasting, and the end result will be stunning!

What Is A Masonry Layout?

A masonry gallery is a popular layout style for displaying elements, such as images, on a website. It is characterized by a grid-like structure where each item is positioned closely together, creating an organized and visually appealing arrangement. Unlike traditional grid layouts where all items have a fixed width and height, a masonry gallery allows for varying heights of items within a row. This results in a dynamic and fluid layout, with items aligning vertically based on their content’s height. The overall effect is a visually interesting and harmonious display of images or content that breaks away from the rigid structure of traditional grid layouts.

Step 1: Add the Divi Gallery Module

Insert the Divi Gallery module into your page. You can upload your images and configure the gallery settings using the module’s options. Make sure to select “Grid” under Design -> Layout.


Step 2: Insert the CSS Code

Next, add the provided CSS code to your site. This CSS code adjusts the column count and spacing based on different screen sizes.

There are several methods to add Divi custom CSS to their websites. These methods include:

Learn all methods from this article >>

To add CSS to page settings, from the front-end Divi visual builder, click on the Divi + icon to reveal the full menu selection. Click on the gear icon and you’ll reveal the Divi Page Settings. Within the Divi Builder Page Settings, go to Advanced Tab and paste the provided CSS into the Custom CSS box.

Customize the CSS to adjust the column count and spacing if needed – see the CSS comments for reference.

Masonry Gallery by WP Zone

.wpz-gallery-masonry .et_pb_gallery .et_pb_gallery_items {
    column-count: 3; /* number of columns for desktop */
    column-gap: 15px;  /* column spacing */

@media only screen and (max-width: 1200px) { 
.wpz-gallery-masonry .et_pb_gallery .et_pb_gallery_items { 
    column-count: 2;  /* number of columns for tablet devices */
@media only screen and (max-width: 767px) {
  .wpz-gallery-masonry .et_pb_gallery .et_pb_gallery_items {
    column-count: 1;  /* number of columns for mobile devices */

.wpz-gallery-masonry .et_pb_gallery .et_pb_gallery_items .et_pb_gallery_item {
    width: 100%;
    margin: 0px 0px 10px 0!important; /* replace 10px to change row spacing */
    float: none!important; 

Step 3: Add the Custom CSS Class

To apply the masonry layout to your gallery, you need to add a custom CSS class “wpz-gallery-masonry” to the section or row that contains the Divi Gallery module.  Edit the section or row, navigate to the Advanced tab, and find the CSS Class option. Enter “wpz-gallery-masonry” as the custom CSS class and save your changes.


Save your page and preview it to see the Divi masonry gallery layout in action!

Does this snippet (still) work?

Please let us know in the comments if everything worked as expected. We have tested this code with the Version: 4.5.3 of the Divi Theme.
If you think this code saved you time, we will be happy to receive a comment!


License: This snippet contains code from the Divi Theme, copyright, modified by WP Zone, November 13, 2019. Licensed under the GNU General Public License, no warranty; click here for details.

Your Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Receive notifications about our new blog posts.

Previous snippet Search WooCommerce Products and Tags With Divi's Search Module