{"id":10951,"library":"glightbox","title":"GLightbox","description":"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.","status":"active","version":"3.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/biati-digital/glightbox","tags":["javascript","lightbox","gallery","popup","typescript"],"install":[{"cmd":"npm install glightbox","lang":"bash","label":"npm"},{"cmd":"yarn add glightbox","lang":"bash","label":"yarn"},{"cmd":"pnpm add glightbox","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"GLightbox is a default export when using bundlers like Webpack or Rollup. The library ships with TypeScript types.","wrong":"import { GLightbox } from 'glightbox';","symbol":"GLightbox","correct":"import GLightbox from 'glightbox';"},{"note":"When loading GLightbox via a script tag (e.g., from a CDN), it exposes the `GLightbox` constructor globally on the `window` object. Do not attempt to use `import` syntax after a global script load.","wrong":"import GLightbox from 'glightbox'; // after script tag load","symbol":"GLightbox","correct":"<script src=\"https://cdn.jsdelivr.net/npm/glightbox/dist/js/glightbox.min.js\"></script>\n<script>const lightbox = GLightbox();</script>"},{"note":"The GLightbox styles are not automatically included with the JavaScript. You must explicitly import the CSS file or link it in your HTML for the lightbox to be styled correctly.","wrong":"/* No CSS import */","symbol":"CSS","correct":"import 'glightbox/dist/css/glightbox.min.css';"}],"quickstart":{"code":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>GLightbox Quickstart</title>\n    <!-- Essential: Link the GLightbox CSS -->\n    <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css\" />\n</head>\n<body>\n    <h1>GLightbox Gallery Example</h1>\n\n    <div class=\"gallery\">\n        <!-- Simple image with title and description -->\n        <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.\">\n            <img src=\"https://picsum.photos/id/1015/300/200\" alt=\"Forest Path\" style=\"width:150px; height:auto;\">\n        </a>\n        <!-- Another image in the same gallery -->\n        <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.\">\n            <img src=\"https://picsum.photos/id/1018/300/200\" alt=\"Mountain Lake\" style=\"width:150px; height:auto;\">\n        </a>\n        <!-- YouTube video example -->\n        <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.\">\n            <img src=\"https://img.youtube.com/vi/dQw4w9WgXcQ/mqdefault.jpg\" alt=\"Rick Roll Thumbnail\" style=\"width:150px; height:auto;\">\n        </a>\n    </div>\n\n    <!-- Essential: Link the GLightbox JavaScript -->\n    <script src=\"https://cdn.jsdelivr.net/npm/glightbox/dist/js/glightbox.min.js\"></script>\n    <script type=\"text/javascript\">\n        // Initialize GLightbox. The selector targets all elements with the 'glightbox' class.\n        const lightbox = GLightbox({\n            selector: '.glightbox', \n            loop: true, // Allow looping through the gallery\n            autoplayVideos: true // Automatically play videos when opened\n        });\n\n        // You can access the GLightbox instance for programmatic control if needed.\n        // console.log('GLightbox initialized:', lightbox);\n    </script>\n</body>\n</html>","lang":"javascript","description":"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."},"warnings":[{"fix":"Review the official GLightbox v4 migration guide (when available) before attempting to upgrade. For production, consider staying on the stable `v3.x` branch until `v4.0.0` is officially released.","message":"GLightbox `v4.x` is currently in beta and introduces significant changes and refactors. Upgrading from `v3.x` will likely require modifications to your implementation due to API changes and a shift towards a plugin-based architecture.","severity":"breaking","affected_versions":">=4.0.0-beta"},{"fix":"Always link `glightbox.min.css` in your HTML `<head>` or import it into your main CSS/SCSS file if using a bundler (e.g., `import 'glightbox/dist/css/glightbox.min.css';`).","message":"The GLightbox CSS stylesheet must be explicitly included in your project. The JavaScript bundle does not automatically inject the styles, leading to an unstyled or non-functional lightbox if omitted.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify that the `selector` string passed to `GLightbox()` matches the CSS class or attribute of your `<a>` tags. For example, if your links have `class=\"my-lightbox-item\"`, initialize with `GLightbox({ selector: '.my-lightbox-item' });`","message":"When initializing GLightbox, ensure the `selector` option accurately targets the elements you intend to trigger the lightbox. Mismatched selectors are a common cause of the lightbox not opening.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `glightbox.min.js` is linked via a `<script>` tag in your HTML (preferably at the end of `<body>`), or properly imported via ESM/CommonJS if using a module bundler. If using a script tag, make sure your initialization script runs after `glightbox.min.js` has loaded.","cause":"The GLightbox JavaScript file has not been loaded or is loaded incorrectly, or you are trying to use it before it's available.","error":"Uncaught ReferenceError: GLightbox is not defined"},{"fix":"Double-check the `href` attribute of your `<a>` tag. For external content, ensure it's publicly accessible. If linking to URLs without clear file extensions (e.g., a dynamic image URL or a generic API endpoint), explicitly set the `data-type` attribute (e.g., `data-type=\"image\"` or `data-type=\"video\"`) on the `<a>` tag.","cause":"The linked media URL is incorrect, inaccessible (e.g., CORS issues for iframes/local files), or GLightbox cannot determine its content type.","error":"Lightbox opens but content (image/video) is blank or shows a loading spinner indefinitely."}],"ecosystem":"npm"}