A dark photo gallery with a lightbox built on the Bootstrap 6 Dialog component. Clicking a thumbnail opens the photo large, with a caption, a "1 / 6" counter and previous/next buttons. Arrow keys and swipe gestures also change the photo. Use it for portfolios, project galleries, product photos or blog image sets.
How it works
The root .ilb-root (pinned to data-bs-theme="dark") contains a heading and a ul.ilb-grid of button.ilb-thumb elements. Each button carries the large image URL in data-ilb-src, a title in data-ilb-title and a caption in data-ilb-meta. Its <img> alt text is reused in the lightbox. Each button opens the single <dialog class="dialog dialog-xl ilb-dialog"> through data-bs-toggle="dialog".
script.js reads all photos from the thumbnails once. On show.bs.dialog it uses event.relatedTarget to find out which thumbnail was clicked and shows that photo. .ilb-prev and .ilb-next wrap around at the ends. A keydown listener on the dialog handles ArrowLeft and ArrowRight, and pointer events on .ilb-image detect a horizontal swipe. Neighbouring photos are preloaded, and .is-loading dims the image while the next one loads. Inside the fixed-height .ilb-stage, portrait and landscape photos are letterboxed with object-fit: contain.
The photos come from Unsplash; replace them with your own images.
Customization
--ilb-accenton.ilb-root: the color of the kicker, the active counter number and the focus outlines.grid-template-columnson.ilb-grid: 2 columns on phones and 3 from 768px; use 4 for larger sets.--bs-dialog-widthon.ilb-dialogandheighton.ilb-stage: the size of the lightbox and of the image area.--bs-dialog-backdrop-bgon.ilb-dialog: how dark the page behind the photo becomes.- Add a photo by copying an
liand settingdata-ilb-src,data-ilb-title,data-ilb-metaand thealttext; the counter updates itself. data-ilb-autoopen="0"opens the first photo on load for the preview. Remove it in production.
Use cases
- Portfolios: thumbnails open the photo large with a caption and a counter such as 1 / 6
- Project galleries: previous and next buttons, arrow keys and swipe gestures change the photo
- Product photo sets: portrait and landscape images fit the stage without being cropped
- Blog image sets: neighbouring photos are preloaded so browsing feels quick
Accessibility
Thumbnails are real buttons with a visible focus outline. Their images have descriptive alt text, which the lightbox image reuses. The dialog is labelled by the photo title, and the counter is an aria-live region, so changes are announced. The previous, next and close buttons have aria-labels. Escape closes the dialog, and focus returns to the thumbnail that opened it. Hover zoom and image fades are disabled under prefers-reduced-motion.
Bootstrap 6 notes
This is built on Bootstrap 6.0.0-alpha.1, and alpha APIs can still change. The BS5 modal modal-xl + modal-dialog + modal-content wrappers become one <dialog class="dialog dialog-xl">. Events are show.bs.dialog and shown.bs.dialog, and relatedTarget still points to the trigger. Icon buttons use btn-icon, and btn-close no longer needs btn-close-white on dark backgrounds.