A lithographic apparatus comprises an illumination system, a support
constructed to support a patterning device, and a projection system. In
pixel grid imaging, a large number of small optical spots are imaged onto
the substrate surface using a micro-lens array (MLA). The z position of
the MLA is adjustable in order to focus the spots on the substrate
surface and/or to compensate for differences in height of the substrate
surface. The focusing adjustment is based on an output of an ultrasonic
distance sensor provided in the vicinity of the substrate surface.