Short-video apps all share one interaction: a full-screen vertical feed where each swipe snaps to the next video and only the visible one plays. You can build that feel on the web with CSS scroll snapping and an IntersectionObserver, no framework needed. This post walks through a version that also works with the keyboard and respects reduced-motion settings.
The markup
<main class="feed" tabindex="0" aria-label="Video feed"> <section class="item"><video src="clip1.mp4" muted loop playsinline preload="metadata"></video></section> <section class="item"><video src="clip2.mp4" muted loop playsinline preload="metadata"></video></section> <section class="item"><video src="clip3.mp4" muted loop playsinline preload="metadata"></video></section> </main> muted and playsinline matter: mobile browsers only allow autoplay for muted, inline video. preload="metadata" keeps the page from downloading every clip up front.
Snap scrolling with CSS
.feed { height: 100dvh; overflow-y: auto; scroll-snap-type: y mandatory; overscroll-behavior: contain; } .item { height: 100dvh; scroll-snap-align: start; scroll-snap-stop: always; display: grid; place-items: center; background: #000; } .item video { max-height: 100%; max-width: 100%; aspect-ratio: 9 / 16; object-fit: contain; } @media (prefers-reduced-motion: reduce) { .feed { scroll-behavior: auto; } } -
100dvh(dynamic viewport height) avoids the classic mobile bug where the address bar makes100vhtoo tall. -
scroll-snap-stop: alwaysstops a fast flick from skipping several videos at once. -
overscroll-behavior: containprevents the page behind the feed from bouncing.
Play only the visible video
const videos = document.querySelectorAll('.feed video'); const observer = new IntersectionObserver(entries => { for (const entry of entries) { const video = entry.target; if (entry.isIntersecting && entry.intersectionRatio >= 0.6) { video.play().catch(() => {}); } else { video.pause(); } } }, { threshold: [0, 0.6, 1] }); videos.forEach(v => observer.observe(v)); A threshold of 0.6 means a video starts once most of it is on screen, so two videos never play at the same time mid-swipe. The empty catch swallows the promise rejection browsers throw when autoplay is blocked.
Keyboard support
Scroll snapping already works with Page Up / Page Down when the feed has focus, but arrow keys feel more natural:
const feed = document.querySelector('.feed'); feed.addEventListener('keydown', e => { if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return; e.preventDefault(); const step = feed.clientHeight * (e.key === 'ArrowDown' ? 1 : -1); const smooth = !matchMedia('(prefers-reduced-motion: reduce)').matches; feed.scrollBy({ top: step, behavior: smooth ? 'smooth' : 'auto' }); }); Add M to toggle sound on the current video and you have most of the desktop experience:
feed.addEventListener('keydown', e => { if (e.key.toLowerCase() !== 'm') return; const current = [...videos].find(v => !v.paused); if (current) current.muted = !current.muted; }); Loading more items
Observe the last item with a second observer and append the next batch when it comes into view. Keep the DOM small by removing items far above the viewport once the list grows past a few dozen; each <video> element holds decoder resources even when paused.
Accessibility notes
- Give each item a heading or
aria-labelwith the video title so screen-reader users know where they are. - Never autoplay with sound.
- Provide visible play/pause and mute buttons; keyboard shortcuts alone are not discoverable.
See it in practice
Browser-based tools for watching short videos use exactly this pattern. A TikTok viewer in the browser is a good reference for the finished feel: one video per screen, snapping between items, and playback that follows what is visible.