Change Divi Image Portfolio Grid Thumbnail Sizes

Written by Dan Mossop

The Divi Theme’s portfolio module gives you the option of displaying your projects as a series of thumbnails (grid view). To adjust the size and spacing of the images in your thumbnail grid, you can use the following CSS:

/* Set the image widths */
.et_pb_portfolio_grid .et_pb_portfolio_item,
.et_pb_portfolio_grid .column_width,
.et_pb_portfolio_grid .et_pb_portfolio_image,
.et_pb_portfolio_grid .et_pb_portfolio_image.portrait img
{
    width: 250px !important;
}
.et_pb_portfolio_grid .et_pb_portfolio_image img
{
    min-width: 250px;
}

/* Set the image heights */
.et_pb_portfolio_grid .et_pb_portfolio_image,
.et_pb_portfolio_grid .et_pb_portfolio_image.landscape img
{
    height: 250px !important;
}
.et_pb_portfolio_grid .et_pb_portfolio_image img
{
    min-height: 250px;
}

/* Set the spacing between images */
.et_pb_portfolio_grid .et_pb_portfolio_item { 
	margin-bottom:26px !important; 
	margin-right: 26px !important; 
}
.et_pb_portfolio_grid .et_pb_portfolio_item.last_in_row {
	margin-right: 0 !important;
}

It looks complex, but it’s very simple to change it to suit your needs. There are three parts. First we set the image width to 250px. Then we set the height to 250px (to get square images, in this case). Finally we set the space between adjacent images to be 26px.

The width normally available to the portfolio images is 1080px and if the images are taking up too much space the ones on the end will be pushed down to the next row. So if you want 4 images per row, make sure that 4*width + 3*spacing <= 1080px.

Craft Stunning Divi Galleries with Ease!

Bring your Divi image grids to life with Divi Gallery Booster, perfect for customizing gallery modules seamlessly. Adjust thumbnail sizes, spacing, and more to create eye-catching visual portfolios.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

30 Comments

  1. Hi,
    Thank you for this very useful CSS. I have applied it to my site. The problem I'm having is that my images are now fuzzy like they are being blown up. Is there any fix for that?

    Reply
    • Hey Julie, are you still having trouble with this? I took a look at the site linked in the comment. I can see a filterable portfolio on the homepage, but the code above in its current form only applies to standard portfolio modules, so I'm not quite sure if you've changed the module or were having the issue elsewhere? If you're still trying to get it to work, perhaps you can confirm the location of the portfolio for me? Thanks!

      Reply
  2. Hi, where do I have to put this CSS? I've never changed the CSS details using the divi theme. Thanks!

    Reply
    • Hi Ricardo, I've just updated the post with a link to this one:

      https://divibooster.com/adding-css-to-the-divi-theme/

      It explains some of the options for adding CSS to Divi. Usually pasting the code into the "Divi > Theme Options > General > Custom CSS" box will work, as it should for the code in this post. I hope that helps.

      Reply
  3. Hi, I need to change my portfolio margin. I change it in my child theme, css file
    .et_pb_portfolio_grid .et_pb_portfolio_item {
    margin: 0 1px 1px 0!important;
    }
    But nothing change. I don't understand why?

    Reply
    • Hi calamy, that CSS seems to be correct, so there's is likely either a problem in how it is being added, or some other CSS conflicting with it. If you haven't already, I'd try adding it into the "Divi > Theme Options > General > Custom CSS" box (to rule out an issue such as broken CSS elsewhere in the child theme style.css). Also, make sure you clear your browser cache and any caches in use on the site (e.g. in performance plugins). If that doesn't help, are you able to send me a link so that I can take a look? Thanks!

      Reply
  4. I would like to center my portfolio grid and tried adding display: flex and justify-content: center but neither seem to work. What is the class I would need to add this to?

    Reply
    • Hi Becca, did you manage to solve this? I took a look at your site (as linked in your comment) and the portfolio on the homepage seems to be correctly centered on desktop and mobile. If your working on another page, are you able to send me a link? Or if I've missed something, please let me know! Thanks.

      Reply
  5. UPDATE: Aside from Dan's awesome CSS tweaks, I updated my functions.php file in my child theme to change the actual thumbnail that Divi produces. Right now, Divi appends _400x284 to your image. I wanted a square ratio and thumbs that were 250px x 250px so I added this filter:

    // Begin custom image size for Portfolio Thumbs
    add_filter( 'et_pb_portfolio_image_height', 'port_size_h' );
    add_filter( 'et_pb_portfolio_image_width', 'port_size_w' );

    function port_size_h($height) {
    return '250';
    }

    function port_size_w($width) {
    return '250';
    }

    add_image_size( 'custom-port-size', 250, 250 );
    // End custom image size for Portfolio Thumbs

    Simply change any reference to 250 to the sizes you want.

    Reply
    • Great! Thanks for sharing your solution, Chris :)

      Reply
    • This is exactly what I've been scouring the Internet to find. Thanks Chris!

      Reply
  6. This changes the overlaying div but not the image thumbnail itself, which causes a "zoom" effect on the images. I want to change the actual thumbnail reference in the file in includes > builder > module > FilterablePortfolio.php – starting on line 371

    This file references et_pb_portfolio_image. Can I put a filter in my functions.php to overwrite this current setting of 400px for height, and 284px for width so the thumbnail does not put "x400x284.png" on the end of the file? Could I then regenerate the thumbnail to my new size?

    Reply
  7. This is super helpful! Using your code helped me adjust the margins and image sizes. However, on different mobile device widths I would sometimes get a wrapped 4 column row, meaning the four images in each row would turn into a 3 image row and then 1 image row and repeat. To fix this, I simply changed the px into % (23% for 4 columns) and it fixed the problem.

    Overall, this was the code I needed. Thanks so much!

    Reply
  8. Very clear and helpful. Thank you!

    Reply
  9. I have tried the CSS code in the "main" and "portfolio" CSS sections and the thumbnail size never changes. I also have Divi Booster and update the image size there, but again the thumbnail size is not changing.

    any idea why it's not responding?

    Thanks
    Adam

    Reply
    • Hi Adam, if you're manually adding the CSS, it should be added either via the theme options custom CSS box, or via a child theme. This post explains in more detail:

      https://divibooster.com/adding-css-to-the-divi-theme/

      Note that adding it in the "main" or "portfolio" CSS sections won't work. The reason is that these areas only accept CSS properties, rather than the full CSS rules given in the code above.

      As for why Divi Booster isn't working, I'd suggest first making sure that it isn't a caching issue by following this post:

      https://divibooster.com/divi-booster-and-caching/

      If that doesn't help, is there any chance you can send me a link to the affected page, so that I can take a look?

      Reply
  10. I want to use this on the filterable portfolio – how would I go about this? Thank for your help.

    Reply
  11. I don't have the Divi Booster…Just Divi 2.5 I want my thumbs have a square format, how can I do that?

    Reply
    • Hi Dany, do you have a link to the page you're trying to set square thumbs on? The above should work for the standard portfolio module, but perhaps you're using something else (like a gallery module, full width portfolio module, etc)?

      Reply
  12. It would be great to know where to use this code.

    Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.

Latest From Divi Booster

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Random Divi Posts