GLightbox

3.3.1 · active · verified Sun Apr 19

GLightbox is a lightweight, pure JavaScript lightbox library designed for displaying various media types including images, videos (YouTube, Vimeo, self-hosted), iframes, and inline content. It is currently stable at version `3.3.1`, with an active beta release stream (`4.0.0-beta.x`) indicating ongoing development towards a new major version. The library is known for its small footprint (11KB gzipped), responsiveness across devices, and comprehensive feature set including gallery support, responsive images, keyboard and touch navigation, zoomable images, and a themeable API. It differentiates itself by being a feature-rich solution without external dependencies, offering a complete lightbox experience out-of-the-box, making it a robust choice for modern web projects requiring media presentation. While minor bug fixes and improvements are released frequently for the v3 branch, the v4 branch represents a significant refactor and enhancement effort.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic image and video gallery using GLightbox by including its CSS and JavaScript files from a CDN, and initializing it with a simple configuration. It showcases linking media with `<a>` tags and using `data-gallery` for grouping, and `data-glightbox` for inline titles/descriptions.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GLightbox Quickstart</title>
    <!-- Essential: Link the GLightbox CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css" />
</head>
<body>
    <h1>GLightbox Gallery Example</h1>

    <div class="gallery">
        <!-- Simple image with title and description -->
        <a href="https://picsum.photos/id/1015/1200/800" class="glightbox" data-gallery="mygallery" data-glightbox="title: Forest Path; description: A peaceful path through the woods.">
            <img src="https://picsum.photos/id/1015/300/200" alt="Forest Path" style="width:150px; height:auto;">
        </a>
        <!-- Another image in the same gallery -->
        <a href="https://picsum.photos/id/1018/1200/800" class="glightbox" data-gallery="mygallery" data-glightbox="title: Mountain Lake; description: Serene lake in the mountains.">
            <img src="https://picsum.photos/id/1018/300/200" alt="Mountain Lake" style="width:150px; height:auto;">
        </a>
        <!-- YouTube video example -->
        <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" class="glightbox" data-gallery="mygallery" data-glightbox="title: Rick Astley; description: Never Gonna Give You Up - official music video.">
            <img src="https://img.youtube.com/vi/dQw4w9WgXcQ/mqdefault.jpg" alt="Rick Roll Thumbnail" style="width:150px; height:auto;">
        </a>
    </div>

    <!-- Essential: Link the GLightbox JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/glightbox/dist/js/glightbox.min.js"></script>
    <script type="text/javascript">
        // Initialize GLightbox. The selector targets all elements with the 'glightbox' class.
        const lightbox = GLightbox({
            selector: '.glightbox', 
            loop: true, // Allow looping through the gallery
            autoplayVideos: true // Automatically play videos when opened
        });

        // You can access the GLightbox instance for programmatic control if needed.
        // console.log('GLightbox initialized:', lightbox);
    </script>
</body>
</html>

view raw JSON →