van der Waals heterostructures assembled from atomically thin crystalline layers of diverse two-dimensional solids are emerging as a new paradigm in the physics of materials. We used infrared nanoimaging to study the properties of surface phonon polaritons in a representative van der Waals crystal, hexagonal boron nitride. We launched, detected, and imaged the polaritonic waves in real space and altered their wavelength by varying the number of crystal layers in our specimens. The measured dispersion of polaritonic waves was shown to be governed by the crystal thickness according to a scaling law that persists down to a few atomic layers. Our results are likely to hold true in other polar van der Waals crystals and may lead to new functionalities.