The Justified layout arranges images in rows with consistent height, adjusting image widths to perfectly fill each row. This creates a professional, gallery-style appearance similar to Flickr and Google Photos.
Overview
Justified layout is ideal for photo galleries and image-heavy portfolios. It maintains consistent row heights while varying image widths to create perfectly filled rows without cropping or distorting images.Key Features
- Consistent row heights: Every row has the same height for clean alignment
- No image cropping: Images maintain their original aspect ratios
- Automatic width adjustment: Images scale to fill rows perfectly
- Professional appearance: Gallery-style layout used by major platforms
- Responsive design: Adapts beautifully to any screen size
Configuration Options
Row Height
The target height in pixels for each row in the justified gallery.
150- Compact gallery (more images visible)200- Small preview size250- Default, balanced (recommended)300- Medium size400- Large, detailed view500+- Extra large showcase
Row Height Tolerance
Tolerance for row height variation, expressed as a decimal (0.25 = 25%). This allows rows to be up to 25% shorter or taller than the target height.
0.1(10%) - Very strict, minimal height variation0.25(25%) - Default, balanced flexibility0.5(50%) - More flexible, accommodates diverse aspect ratios1.0(100%) - Maximum flexibility
Higher tolerance values result in better space utilization but more height variation between rows. Lower values maintain stricter consistency but may create awkward gaps.
Implementation Details
Flickr Justified Gallery
Visual Portfolio uses the Flickr Justified Gallery library for its justified layout implementation:Library Integration
The layout uses the Flickr Justified Gallery library located at:assets/vendor/flickr-justified-gallery/dist/fjGallery.min.js
How Justified Layout Works
- Collect images: Gathers all images with their aspect ratios
- Calculate widths: Determines optimal width for each image to fit row height
- Fill rows: Places images in rows until target width is reached
- Adjust to fit: Slightly scales images to perfectly fill each row
- Apply layout: Positions images with calculated dimensions
Usage Examples
Basic Justified Gallery
Compact Photo Gallery
Large Showcase Gallery
Gutenberg Block
In the Block Editor:- Add Visual Portfolio block
- Select Justified layout
- Set Row Height (default: 250)
- Adjust Row Height Tolerance (default: 0.25)
- Configure gap and other styling options
Responsive Behavior
The Justified layout automatically adapts to different screen sizes:- Desktop: Full row height as configured
- Tablet: Slightly reduced row height to accommodate smaller screens
- Mobile: Further reduced row height for better mobile viewing
Best Practices
When to use Justified layout
When to use Justified layout
- Professional photo galleries
- Photography portfolios
- Image-heavy content
- When aspect ratios vary significantly
- Showcasing visual work without cropping
Optimal settings
Optimal settings
- Use 250-300px row height for balanced viewing
- Keep tolerance between 0.2-0.3 for best results
- Use smaller gaps (5-15px) for tighter galleries
- Test with your actual images for best appearance
Performance tips
Performance tips
- Enable lazy loading for galleries with 30+ images
- Optimize image file sizes before uploading
- Use appropriate image dimensions (width: 1200-2000px)
- Enable pagination for very large galleries
Design considerations
Design considerations
- Works best with landscape and portrait mixed images
- Not ideal for galleries with only square images (use Grid instead)
- Ensure images have good composition for any width
- Consider using lightbox for full-size viewing
Common Issues
Justified vs Other Layouts
Justified
✅ No cropping
✅ Professional look
✅ Varied aspect ratios
❌ Last row may be incomplete
✅ Professional look
✅ Varied aspect ratios
❌ Last row may be incomplete
Grid
✅ Consistent sizes
✅ Predictable layout
❌ May crop images
❌ Less flexible
✅ Predictable layout
❌ May crop images
❌ Less flexible
Combining with Features
Justified layout works seamlessly with:- Lightbox: View full-size images in overlay
- Lazy Loading: Improve performance with large galleries
- Filters: Allow users to filter images
- Pagination: Load more images dynamically
Advanced Customization
Developers can customize the justified layout behavior:Related Layouts
Masonry Layout
Dynamic heights with column-based layout
Grid Layout
Uniform grid with consistent sizing
Source Code Reference
- JavaScript:
assets/js/layout-justified.js:1 - Library:
assets/vendor/flickr-justified-gallery/dist/fjGallery.min.js - Default Row Height:
assets/js/layout-justified.js:9 - Default Tolerance:
assets/js/layout-justified.js:10