If the tip were scanned at constant height, there would be a risk that the tip would collide with the surface, causing damage. Hence, in most cases a feedback mechanism is employed to adjust the tip-to-sample distance to keep the force between the tip and the sample constant. This can be achieved by mounting the sample on a piezoelectric crystal.
The tip is then scanned across the sample surface and the vertical displacement s necessary to maintain a constant force on the tip is recorded. The resulting map of s(x,y) represents the topography of the sample.
See also: scanning tunneling microscope