
Photo: Dinopkk, CC BY-SA 3.0, via Wikimedia Commons
"3D audio" gets used loosely, but in the browser it has a precise meaning: placing a sound source at a position in virtual space, relative to a listener, so that panning, distance attenuation, and (optionally) directional cues are computed for you instead of hand-rolled with stereo panning math. The Web Audio API has shipped this natively for years, which means a game, a VR/AR scene, a spatial music piece, or even an accessibility feature (audio cues that tell a user where something is on screen) can all lean on the same built-in nodes.
Every spatialized sound source in the Web Audio API is routed through a PannerNode, which holds a 3D position, orientation, and a set of distance/cone parameters. A single AudioListener per AudioContext represents the "ears" — its position and forward/up orientation vectors are what every PannerNode is positioned relative to. Move the listener (the player's viewpoint, say) or move the source (a car driving past), and the browser recomputes the mix on the next audio render quantum.
PannerNode supports two fundamentally different panning models. 'equalpower' is cheap: it distributes a source's energy across the output channels based on angle, the same idea as a traditional stereo pan pot, extended to more speakers. 'HRTF' (head-related transfer function) is more expensive and more convincing over headphones: it applies a filter that approximates how a real human head, ears, and torso alter a sound's frequency content depending on where it's coming from — the same cue your brain uses to tell whether something is behind you without turning around.
HRTF filtering is built around binaural listening: two independent channels reaching two separate ears with no crosstalk, which is exactly what headphones deliver and exactly what stereo speakers don't (each ear hears a blend of both speakers). That's why a well-tuned spatial mix can feel startlingly precise on headphones and noticeably flatter on laptop speakers — the underlying math assumes an ear-isolation the hardware doesn't always provide. It's a known trade-off in spatial audio design, not a bug in any one implementation.
A few things trip up most first attempts at spatial audio: forgetting to set a realistic distanceModel and rolloff (everything ends up either inaudible at a few meters or audible from across the map), leaving the default HRTF dataset to do more work than it should for close-up sources where distance cues matter more than directional ones, and assuming cross-browser parity — HRTF rendering quality and CPU cost both vary by engine, so a mix that sounds pristine in one browser is worth re-checking in another before shipping.
Spatial audio in the browser is genuinely native, not a plugin or a hack: PannerNode and AudioListener handle the geometry, and the browser handles the DSP. Getting a spatial mix that feels right, though, is still a matter of understanding the panning models, the distance/cone parameters, and the headphones-vs-speakers trade-off well enough to tune them deliberately rather than by trial and error.
Curious what a production 3D audio scene looks like end to end? Try SpaceXYZ, our browser-based 3D audio spatializer, live.