react-masonry-css vs react-masonry-component vs react-responsive-masonry vs react-photo-gallery vs react-grid-gallery
Image Gallery and Masonry Layout Libraries Comparison
1 Year
react-masonry-cssreact-masonry-componentreact-responsive-masonryreact-photo-galleryreact-grid-gallerySimilar Packages:
What's Image Gallery and Masonry Layout Libraries?

Image Gallery and Masonry Layout Libraries are tools designed for React applications to display images in visually appealing and organized ways. These libraries provide various layouts, such as grid, masonry, and gallery styles, allowing developers to showcase images dynamically while maintaining responsiveness and aesthetic appeal. They often come with features like lazy loading, lightbox integration, and customizable styles, making it easier to create engaging image-centric interfaces. These libraries enhance user experience by presenting images in a structured manner, optimizing space usage, and providing smooth interactions.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-masonry-css139,9791,012-294 years agoMIT
react-masonry-component90,1561,460-614 years agoMIT
react-responsive-masonry67,39343470.8 kB296 months agoMIT
react-photo-gallery14,7462,000-806 years agoMIT
react-grid-gallery13,8521,055193 kB22a year agoMIT
Feature Comparison: react-masonry-css vs react-masonry-component vs react-responsive-masonry vs react-photo-gallery vs react-grid-gallery

Layout Type

  • react-masonry-css:

    react-masonry-css implements a pure CSS masonry layout, leveraging CSS Grid or Flexbox to achieve the masonry effect without JavaScript, resulting in better performance.

  • react-masonry-component:

    react-masonry-component offers a masonry layout that allows for dynamic positioning of items based on their size, creating a visually appealing staggered effect.

  • react-responsive-masonry:

    react-responsive-masonry focuses on creating responsive masonry layouts that adjust based on the screen size, ensuring a consistent look across devices.

  • react-photo-gallery:

    react-photo-gallery supports both grid and masonry layouts, allowing for more flexibility in how images are displayed, with advanced features for customizing the layout.

  • react-grid-gallery:

    react-grid-gallery provides a grid layout with lightbox functionality, making it easy to display images in a structured format with the ability to view them in full screen.

Customization

  • react-masonry-css:

    react-masonry-css offers customization through CSS, giving developers full control over the styling of the masonry items and layout without any predefined styles.

  • react-masonry-component:

    react-masonry-component provides good customization options for item styling and layout, allowing developers to create unique designs while maintaining the masonry structure.

  • react-responsive-masonry:

    react-responsive-masonry allows for customization of the masonry layout and item styles, with a focus on maintaining responsiveness across different screen sizes.

  • react-photo-gallery:

    react-photo-gallery is highly customizable, allowing for detailed control over image rendering, spacing, and layout behavior, making it suitable for more complex designs.

  • react-grid-gallery:

    react-grid-gallery allows for basic customization of image sizes, captions, and lightbox styles, but it is relatively limited in terms of layout flexibility.

Lightbox Support

  • react-masonry-css:

    react-masonry-css does not provide lightbox support, as it focuses solely on the masonry layout. Lightbox functionality would need to be implemented separately.

  • react-masonry-component:

    react-masonry-component does not include lightbox functionality by default, but it can be integrated with third-party lightbox components for a complete solution.

  • react-responsive-masonry:

    react-responsive-masonry does not offer lightbox functionality, but it can be combined with lightbox components to create a more interactive image gallery.

  • react-photo-gallery:

    react-photo-gallery does not include lightbox support out of the box, but it can be easily integrated with external lightbox libraries for enhanced image viewing.

  • react-grid-gallery:

    react-grid-gallery includes built-in lightbox support for viewing images in full screen, enhancing the gallery experience with minimal additional setup.

Performance

  • react-masonry-css:

    react-masonry-css is lightweight and performs well, especially for smaller galleries. Its CSS-based approach reduces the need for heavy JavaScript processing.

  • react-masonry-component:

    react-masonry-component performs well with a dynamic number of items, but performance may vary with a large number of items due to the nature of the masonry layout.

  • react-responsive-masonry:

    react-responsive-masonry maintains good performance while ensuring that the masonry layout adapts responsively, though performance can be affected by the number of items and their sizes.

  • react-photo-gallery:

    react-photo-gallery is designed for performance, with features like lazy loading and efficient rendering, making it suitable for galleries with many images.

  • react-grid-gallery:

    react-grid-gallery is optimized for performance with lazy loading and efficient rendering of images, making it suitable for galleries with a moderate number of images.

Ease of Use: Code Examples

  • react-masonry-css:

    CSS-Only Masonry Layout

    import React from 'react';
    import { Masonry } from 'react-masonry-css';
    import './styles.css'; // Custom CSS for styling
    
    const MyMasonry = () => (
      <Masonry
        breakpointCols={{ default: 3, 768: 2, 480: 1 }}
        className='my-masonry'
        columnClassName='my-masonry-column'
      >
        <div className='masonry-item'>Item 1</div>
        <div className='masonry-item'>Item 2</div>
        <div className='masonry-item'>Item 3</div>
      </Masonry>
    );
    
    export default MyMasonry;
    
  • react-masonry-component:

    Masonry Layout with Dynamic Items

    import React from 'react';
    import Masonry from 'react-masonry-component';
    
    const masonryOptions = {
      transitionDuration: '0.4s',
    };
    
    const MyMasonry = () => (
      <Masonry
        options={masonryOptions}
        className='my-masonry'
      >
        <div className='masonry-item'>Item 1</div>
        <div className='masonry-item'>Item 2</div>
        <div className='masonry-item'>Item 3</div>
      </Masonry>
    );
    
    export default MyMasonry;
    
  • react-responsive-masonry:

    Responsive Masonry Layout

    import React from 'react';
    import { Masonry } from 'react-responsive-masonry';
    
    const MyResponsiveMasonry = () => (
      <Masonry
        columnsCountBreakPoints={{ 350: 1, 750: 2, 900: 3 }}
      >
        <div style={{ padding: '10px' }}>Item 1</div>
        <div style={{ padding: '10px' }}>Item 2</div>
        <div style={{ padding: '10px' }}>Item 3</div>
      </Masonry>
    );
    
    export default MyResponsiveMasonry;
    
  • react-photo-gallery:

    Customizable Photo Gallery

    import React from 'react';
    import Gallery from 'react-photo-gallery';
    
    const photos = [
      { src: 'image1.jpg', width: 4, height: 3 },
      { src: 'image2.jpg', width: 1, height: 1 },
      { src: 'image3.jpg', width: 3, height: 4 },
    ];
    
    const MyGallery = () => <Gallery photos={photos} />;
    
    export default MyGallery;
    
  • react-grid-gallery:

    Simple Grid Gallery with Lightbox

    import React from 'react';
    import Gallery from 'react-grid-gallery';
    
    const images = [
      {
        src: 'image1.jpg',
        thumbnail: 'image1_thumb.jpg',
        thumbnailWidth: 150,
        thumbnailHeight: 150,
        caption: 'Image 1',
      },
      {
        src: 'image2.jpg',
        thumbnail: 'image2_thumb.jpg',
        thumbnailWidth: 150,
        thumbnailHeight: 150,
        caption: 'Image 2',
      },
    ];
    
    const MyGallery = () => <Gallery images={images} />;
    
    export default MyGallery;
    
How to Choose: react-masonry-css vs react-masonry-component vs react-responsive-masonry vs react-photo-gallery vs react-grid-gallery
  • react-masonry-css:

    Opt for react-masonry-css if you prefer a lightweight, CSS-only solution for masonry layouts. It’s great for projects that prioritize performance and simplicity without the need for additional JavaScript.

  • react-masonry-component:

    Select react-masonry-component if you want a flexible masonry layout that allows for dynamic item sizing. It’s suitable for applications where items have varying heights and you need a more customizable layout.

  • react-responsive-masonry:

    Choose react-responsive-masonry if you need a responsive masonry layout that adapts to different screen sizes. It’s ideal for mobile-friendly applications where layout flexibility is crucial.

  • react-photo-gallery:

    Use react-photo-gallery for a highly customizable gallery that supports both grid and masonry layouts. It’s perfect for projects that require more control over the layout and styling of images.

  • react-grid-gallery:

    Choose react-grid-gallery if you need a simple yet effective grid gallery with lightbox support. It’s ideal for projects that require a straightforward implementation with minimal configuration.

README for react-masonry-css

A Masonry component leveraging CSS and native React rendering, for fast, responsive masonry layouts

image

😎 Why?

Existing solutions like React wrapped DeSandro Masonry, while popular, don't actually leverage React's highly optimized Virtual DOM renderer and in DeSandro Masonry's case, actually renders elements twice before showing the layout. All of this is ok but we found it to lead to a slow, "laggy" user experience that would occasionally miss-render our layout.

Our need for a simple Masonry layout that was fast, used React's Virtual DOM without needing jQuery or other dependencies led us to explore what we could do with the latest techniques using just CSS within a React Component.

Between flexbox, css columns, css grid we settled on plain ol' div's and a dab of flexbox that allows for "fluid" responsive layouts by default but most importantly is true to Reacts rendering lifecycle.

react-masonry-css Is a React Component with a simple interface to order items into the desired columns at specified breakpoints. With minimal CSS this leads to a quick, reliable solution that also has great browser support along with rendering performance.

😄 What does this do

  • Responsive! ..always
  • IE 10+
  • No Dependencies - Which means no need for jQuery!
  • Works with existing CSS animations on your elements, like fading in on first load
  • CSS powered (Faster to render)
  • Allows for Gaps (Gutters) between elements

🏳️ What doesn't this do

  • Works with elements with different widths
  • Sorting based on height - This kills performance, so if you don't need it we're here for you

😲 Simple Usage

Add react-masonry-css to your project:

npm install react-masonry-css

In your React Component...

import Masonry from 'react-masonry-css'

//...

<Masonry
  breakpointCols={3}
  className="my-masonry-grid"
  columnClassName="my-masonry-grid_column">
  {/* array of JSX items */}
</Masonry>

And, CSS:

.my-masonry-grid {
  display: -webkit-box; /* Not needed if autoprefixing */
  display: -ms-flexbox; /* Not needed if autoprefixing */
  display: flex;
  margin-left: -30px; /* gutter size offset */
  width: auto;
}
.my-masonry-grid_column {
  padding-left: 30px; /* gutter size */
  background-clip: padding-box;
}

/* Style your items */
.my-masonry-grid_column > div { /* change div to reference your elements you put in <Masonry> */
  background: grey;
  margin-bottom: 30px;
}

Responsive Breakpoints

Different columns can be specified by passing an object containing key's of the window widths and their value as the number of columns. To have a fallback value, use the default key.


const breakpointColumnsObj = {
  default: 4,
  1100: 3,
  700: 2,
  500: 1
};

//...

<Masonry
  breakpointCols={breakpointColumnsObj}
  className="my-masonry-grid"
  columnClassName="my-masonry-grid_column"
>
  <div>My Element</div>
  <div>My Element</div>
  <div>My Element</div>
  <div>My Element</div>
</Masonry>

Configuration Props

  • breakpointCols={{default: 4, 800: 2}} optional (defaults to 2 columns)
  • className for the container
  • columnClassName class name added to each generated column

Example Demo

https://paulcollett.github.io/react-masonry-css/demo/

Common usage

outputting an array of items:

var items = [
  {id: 1, name: 'My First Item'},
  {id: 2, name: 'Another item'},
  {id: 3, name: 'Third Item'},
  {id: 4, name: 'Here is the Fourth'},
  {id: 5, name: 'High Five'}
];

// Convert array to JSX items
items = items.map(function(item) {
  return <div key={item.id}>{item.name}</div>
});

<Masonry
  breakpointCols={myBreakpointsAndCols}
  className="my-masonry-grid"
  columnClassName="my-masonry-grid_column"
>
  {items}
</Masonry>

Optional, Responsive gutters

We can add the following to the above CSS to further adjust the layout between screen sizes.

/* Optional, different gutter size on mobile */
@media (max-width: 800px) {
  .my-masonry-grid {
    margin-left: -15px; /* gutter size offset */
  }
  .my-masonry-grid_column {
    padding-left: 15px; /* gutter size offset */
  }
  .my-masonry-grid_column > div {
    margin-bottom: 15px; /* space between items */
  }
}

Use with Preact

You can use react-masonry-css with Preact when using preact/compat

DummyJS

Improve your frontend builds with dynamic placeholder images and dummy text from DummyJs.com. https://www.npmjs.com/package/dummyjs

Suggestions & Issues

https://github.com/paulcollett/react-masonry-css/issues/

Contact me direct:

  • https://github.com/paulcollett
  • http://paulcollett.com