A dark, responsive Bootstrap 5 photo grid where every image carries a colored category label and an overlay caption, with filter buttons to show one category at a time. It suits portfolios, photo journals, travel blogs and image-heavy landing pages.
How it works
The root section.pg-root holds a heading row and a ul.pg-grid. Bootstrap utilities lay out the heading and the .pg-filters button group, which sit side by side from the md breakpoint and stack on phones. The grid itself is CSS Grid: two columns on small screens and four from 768px, with a fixed row height from --pg-row and grid-auto-flow: dense so the larger tiles leave no gaps. .pg-item--feature spans two columns and two rows, and .pg-item--tall spans two rows.
Every li.pg-item contains a figure.pg-figure with an img set to object-fit: cover, a Bootstrap badge with a category modifier such as .pg-badge--nature, and a figcaption.pg-caption with a title and a meta line on a dark gradient for readable text. Captions are always visible, and on hover the photo zooms slightly.
The script runs on DOMContentLoaded for each .pg-root. It counts the items per data-pg-category value and writes the numbers into the .pg-filter__count spans. Clicking a button with data-pg-filter sets the hidden attribute on items from other categories, updates aria-pressed on all buttons and writes a short result into the visually hidden .pg-status region. Shown items fade back in with the pg-fade keyframes. Without JavaScript, all photos stay visible.
Customization
--pg-accenton.pg-rootinstyle.css: changes the kicker text, the active filter and the focus ring.--pg-rowand--pg-gapon.pg-root: set the row height and the spacing; the 768px media query overrides both for larger screens.grid-template-columns: repeat(4, 1fr)in the.pg-gridmedia query: use 3 or 5 columns on desktop.- Add
.pg-item--featureor.pg-item--tallto anyli.pg-itemto make that photo larger. data-pg-categoryon an item and a matchingdata-pg-filterbutton: add a new category; the counts update automatically..pg-badge--nature,.pg-badge--city,.pg-badge--food,.pg-badge--animals: change each label color or add a modifier for a new category.--pg-bgand--pg-texton.pg-root: switch the section to a light palette.
Use cases
- Photography portfolios: visitors filter photos by category with live counts on each button
- Travel blogs: nature, city and food photos carry colored category labels and overlay captions
- Photo journals: a larger featured tile and tall tiles make the grid feel varied
- Image-heavy landing pages: a dark responsive grid with a hover zoom shows work at its best
- Agency sites: show the number of results through a screen reader status message
Accessibility
The grid is a list, each photo is a figure with a figcaption, and every image has a descriptive alt. The filter buttons are real buttons in a role="group" with an aria-label, and aria-pressed tells screen readers which filter is active. The .pg-status live region announces how many photos are shown. Filter buttons have a visible :focus-visible outline. Under prefers-reduced-motion the fade animation and the hover zoom are disabled.
Usage notes
Requires Bootstrap 5, which is loaded automatically; no icon font is needed. The photos come from Unsplash; replace them with your own images and keep the width and height attributes to avoid layout shift. Each .pg-root filters independently, so several galleries can share a page.