Back to Snippets

View Transitions Grid Filter JS

A grid of project cards with a row of filter buttons above it. Pick a category and the cards that stay glide to their new positions while the others fade out.

The filtering is ordinary. Each button toggles the hidden attribute on the cards that do not match. The motion comes from wrapping that update in document.startViewTransition. The browser snapshots the grid, applies the change, snapshots again and animates between the two. Every card carries its own view-transition-name, set once from its id, which lets the browser follow a card from its old spot to its new one instead of cross-fading the whole grid.

Same-document view transitions are in Chrome, Edge and Safari, and Firefox 144 added them in October 2025. The script checks for startViewTransition first and falls back to applying the filter immediately, so the grid still works everywhere.

0
#javascript
#css
#view transitions
#filter
#gallery
#grid
#animation
#ui