Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-photo-album

> 前端框架
Open source

Responsive photo gallery component for React

780 stars0 likes1 views
WebsiteGitHub

About

Responsive photo gallery component for React

Overview

  • Built for React: works with React 18+
  • SSR friendly: produces server-side rendered markup that looks pixel-perfect on the client even before hydration
  • Responsive images: responsive images with automatic resolution switching are supported out of the box
  • Feature-packed: supports 3 layout options (rows, columns, and masonry), responsive images, custom data attributes, and is fully configurable and customizable
  • TypeScript: type definitions come built-in with the package
  • Performance: built with performance in mind to support large photo albums

Layouts

Rows

Columns

Masonry

Documentation

https://react-photo-album.com/documentation

Examples

https://react-photo-album.com/examples

Changelog

https://github.com/igordanchenko/react-photo-album/releases

Installation

bash
npm install react-photo-album

Requirements

  • React 18+
  • Node 18+
  • modern ESM-compatible bundler

Minimal Setup Example

typescript
import { RowsPhotoAlbum } from "react-photo-album";
import "react-photo-album/rows.css";

const photos = [
  { src: "/image1.jpg", width: 800, height: 600 },
  { src: "/image2.jpg", width: 1600, height: 900 },
];

export default function Gallery() {
  return ;
}

How It Works

Rows Layout

Rows layout fills the container space by arranging photos into rows that are similar in height, with the height of each row being as close to the targetRowHeight as possible. This layout is inspired by the Knuth and Plass line-breaking algorithm and uses dynamic programming to find optimal row breaks in a DAG (directed acyclic graph) where photo indices are nodes and each possible row is an edge connecting its first and last photo. The cost of each edge is a weighted squared deviation from the targetRowHeight. This algorithm produces rows that are similar in height and photos that are not stretched or abnormally shrunk (as happens in a naive implementation). It solves the issue of panoramas shrinking rows, stragglers, or stretched images in the last row.

Columns Layout

Columns layout fills the container space by arranging photos into a predefined number of columns, determined by the columns parameter. This layout uses a dynamic programming algorithm to find the optimal partition of photos into the specified number of groups (columns) that produces the most balanced layout. Column widths are then adjusted proportionally based on their content's aspect ratios so that all columns render at equal height.

Masonry Layout

Masonry layout arranges photos into columns of equal width by placing each photo into the shortest column. This layout does not fill the container space flush to its bottom edge, but the columns end up being as close in height to each other as possible.

Responsive Images

React Photo Album can automatically produce sizes and srcset image attributes. In the case of SSR, React Photo Album includes sizes and srcset image attributes in the server-rendered markup, allowing browsers to pick images of the most appropriate resolution depending on the end-user viewport size. To utilize images with automatic resolution switching, provide images of different resolutions in the photo srcSet attribute. To further improve app responsiveness and bandwidth utilization, you can specify the sizes prop that describes the width of the photo album in various viewports.

…

SSR

React Photo Album extensively uses CSS flexbox and CSS calc functions to calculate images' dimensions on the client. Thanks to this approach, server-side rendered markup looks pixel-perfect on the client even before hydration. To enable server-side rendering, specify the defaultContainerWidth prop. Otherwise, React Photo Album produces empty markup on the server and renders on the client only after hydration. Please note that unless your photo album is of constant width that always matches the defaultContainerWidth value, you will most likely see a layout shift immediately after hydration. Alternatively, you can provide a fallback skeleton in the skeleton prop that will be rendered in SSR and swapped with the actual photo album markup after hydration. Please also refer to the Server-Side Rendering documentation for a comprehensive list of available solutions.

Sponsors

This project is supported by the following companies, organizations, and individuals who help make its continued development and maintenance possible.

Support this project by becoming a sponsor. Both recurring and one-time contributions are very much appreciated.

Credits

Thanks to Sandra G (aka neptunian) for authoring the original react-photo-gallery library that served as inspiration and foundation for react-photo-album.

License

MIT © 2021 Igor Danchenko

Issues· 2 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptgallerygridimage-layoutimages

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架