Skip to content

Filterable Portfolio Gallery

Dark Bootstrap 5 portfolio gallery with pill filter buttons, automatic category counts, fade-in tiles and a screen reader status message.

Also known as: filterable portfolio, portfolio grid with filters, image gallery filter, project gallery

Bootstrap 5 Galleries Responsive Dark #filter #gallery #grid #portfolio #responsive

Filterable Portfolio Gallery live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A dark Bootstrap 5 portfolio gallery with pill-shaped category filter buttons that show or hide project tiles instantly. Use it on agency and freelancer sites, case study pages or any grid of work that needs quick sorting by type.

How it works

The root is section.gf-gallery. The header uses a Bootstrap row with the title on the left and the .gf-filters button group on the right (it wraps under the title on small screens). Each .gf-filter button has a data-filter value and an aria-pressed state. The projects are a ul.gf-grid that uses row-cols-1 row-cols-sm-2 row-cols-lg-3, so the grid goes from one to three columns. Every li.gf-item carries a data-category that matches one of the filter values, and contains a figure.gf-tile with a 4:3 image and a gradient .gf-caption.

On DOMContentLoaded the script handles every .gf-gallery on the page. It first counts the matching items for each button and writes the number into its .gf-count span, so the counts always reflect the markup. Clicking a button sets aria-pressed="true" on it and false on the others, toggles the hidden property on each .gf-item, and re-adds the gf-in class to the visible items to replay the gf-fade keyframes. If nothing matches, the .gf-empty paragraph appears. Without JavaScript all projects stay visible.

Customization

  • --gf-accent in .gf-gallery: changes the active filter pill, the kicker, the tag text and the focus outline (amber by default).
  • --gf-bg and --gf-surface in .gf-gallery: switch the section to another dark tone or to a light background (also adjust --gf-text).
  • --gf-radius in .gf-gallery: round the tiles more or make them square.
  • Add a category by giving a new .gf-filter a data-filter value such as motion and using data-category="motion" on the matching .gf-item; its count is filled in automatically.
  • Set aria-pressed="true" on a different .gf-filter to open the gallery on that category.
  • row-cols-lg-3 on .gf-grid: change to row-cols-lg-4 for a denser four-column grid.
  • aspect-ratio: 4 / 3 in .gf-tile: use 1 / 1 for square thumbnails or 3 / 4 for portrait work.

Use cases

  • Agency websites: pill filter buttons sort work by project type with tiles that fade in
  • Freelancer portfolios: category counts appear automatically beside each filter button
  • Case study pages: visitors narrow a grid of projects down to the type they care about
  • Accessible galleries: a screen reader status message announces how many tiles are showing

Accessibility

The filters are native buttons inside a role="group" with an aria-label, and each exposes its state with aria-pressed. The count numbers are aria-hidden so button names stay short. After every click the visually hidden .gf-status live region announces a message such as "Showing 3 projects in Web." Hidden items use the hidden property, so they are removed from the accessibility tree. Each image has descriptive alt text and the caption is a real figcaption. Buttons get a thick amber :focus-visible outline, and the fade and hover zoom are disabled under prefers-reduced-motion: reduce.

Usage notes

Requires only Bootstrap 5 (added automatically). Several galleries can share a page because the script scopes all queries to each .gf-gallery. Replace the placehold.co images with your own screenshots and keep the width and height attributes to avoid layout shift.

Filterable Portfolio Gallery at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5
Layout
Responsive, works on mobile, dark design
Category
Galleries
License
Free for personal and commercial use

Questions about this template

Can I use the Filterable Portfolio Gallery code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
Filterable Portfolio Gallery – free Bootstrap 5 gallery template
Filterable Portfolio Gallery · free Bootstrap 5 gallery template

More Galleries

CSS Grid Bento Photo Gallery – free Pure CSS gallery template

CSS Grid Bento Photo Gallery

Bento-style photo gallery with mixed tile sizes from CSS Grid spans, hover captions and a keyboard-friendly dialog lightbox.

Polaroid Photo Gallery – free Pure CSS gallery template

Polaroid Photo Gallery

Pure CSS polaroid gallery on a cork board: tilted photo frames with tape and handwritten captions that straighten and lift on hover or focus.

Masonry Image Gallery – free Pure CSS gallery template

Masonry Image Gallery

Pure CSS masonry image gallery using multi-column layout, with hover and focus captions that slide up over each photo. No JavaScript needed.

Before and After Image Slider for Shopify – free Shopify gallery template

Before and After Image Slider for Shopify

Drag-to-compare before and after image slider for Shopify with vertical or horizontal divider, touch and keyboard control, and optional side text.

Gallery with Lightbox – free Tailwind CSS gallery template

Gallery with Lightbox

Tailwind CSS mosaic image gallery that opens an accessible lightbox with captions, arrow-key and swipe navigation, focus trap and preloading.