Yet Another React Lightbox

3.31.0 · active · verified Sun Apr 19

Yet Another React Lightbox (YARL) is a modern, performant, and highly customizable React component designed for displaying images and and videos in a lightbox interface. Currently at stable version 3.31.0, it receives frequent updates, with several patch and minor releases in recent months, indicating an active development cadence. Key differentiators include its focus on responsive images using `srcset` and `sizes` for optimal loading, support for various navigation methods (keyboard, mouse, touch), and a modular architecture that utilizes optional plugins for features like zoom, captions, and video support. It is built to work with React versions 16.8.0 through 19, provides built-in TypeScript definitions, and is compatible with RTL layouts, ensuring broad compatibility and developer experience.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates the minimal setup for Yet Another React Lightbox, showing how to open and close the lightbox and provide a basic array of image slides.

import * as React from 'react';
import Lightbox from 'yet-another-react-lightbox';
import 'yet-another-react-lightbox/styles.css';

export default function App() {
  const [open, setOpen] = React.useState(false);

  return (
    <>
      <button type="button" onClick={() => setOpen(true)}>
        Open Lightbox
      </button>

      <Lightbox
        open={open}
        close={() => setOpen(false)}
        slides={[
          { src: '/image1.jpg' },
          { src: '/image2.jpg' },
          { src: '/image3.jpg' },
        ]}
      />
    </>
  );
}

view raw JSON →