The Masonry layout arranges items in an optimal position based on available vertical space, similar to a mason fitting stones in a wall. This creates a visually appealing, dynamic grid without forced heights.
Overview
Masonry is one of the most popular layout options in Visual Portfolio, creating a Pinterest-style gallery where items of varying heights are arranged efficiently. The layout uses the Isotope library to calculate optimal positioning.Key Features
- Dynamic positioning: Items flow naturally based on available space
- Responsive columns: Automatically adjusts columns based on screen size
- Flexible heights: Each item can have different heights based on content
- Smooth animations: Items animate into position on load and filter
- Performance optimized: Efficient rendering even with many items
Configuration Options
Columns
Number of columns to display in the masonry grid. This automatically adjusts for smaller screens.
2- Two columns (great for large images)3- Three columns (default, balanced layout)4- Four columns (compact gallery)5+- Five or more columns (dense grid)
Horizontal Order
When enabled, items are positioned in horizontal order rather than optimal vertical order.
Image Aspect Ratio
Force a specific aspect ratio for all images in the gallery.
16:9- Widescreen4:3- Standard1:1- Square3:2- Classic photo ratio
Responsive Behavior
The Masonry layout automatically adjusts the number of columns based on screen size:- Desktop: Full column count
- Tablet: Columns - 1
- Mobile: Columns - 2 (minimum 1)
Implementation Details
JavaScript
The Masonry layout is implemented in/assets/js/layout-masonry.js and initializes through the Visual Portfolio event system:
Isotope Integration
Masonry uses the Isotope library for positioning calculations. The layout leverages Isotope’s built-in masonry mode for optimal performance.Usage Examples
Basic Masonry Gallery
Gutenberg Block
In the Gutenberg editor:- Add a Visual Portfolio block
- Select Masonry as the layout
- Configure the number of columns
- Adjust gap and other styling options
Four Column Gallery
Best Practices
When to use Masonry
When to use Masonry
- You have images with varying heights
- You want a dynamic, Pinterest-style layout
- Content has natural height variations
- You’re showcasing portfolio work or photography
Performance tips
Performance tips
- Use image lazy loading for galleries with many items
- Optimize image sizes before uploading
- Consider using fewer columns on mobile devices
- Enable caching if your content doesn’t change frequently
Design considerations
Design considerations
- Ensure sufficient gap between items for readability
- Test on multiple screen sizes
- Consider using consistent aspect ratios for cleaner look
- Be mindful of text overlay readability on varying image heights
Common Issues
Combining with Other Features
Masonry layout works seamlessly with:- Filters: Allow users to filter items while maintaining masonry layout
- Pagination: Load more items dynamically
- Lightbox: Open items in a lightbox overlay
- Item Styles: Apply hover effects and overlays
Related Layouts
Grid Layout
Use Grid for consistent row heights
Tiles Layout
Create custom tile patterns
Source Code Reference
- JavaScript:
assets/js/layout-masonry.js:1 - Isotope Integration:
assets/vendor/isotope-layout/dist/isotope.pkgd.min.js