A confocal displacement sensor with a varifocal lens and a multi-wavelength rainbow laser was established in this study. The surface curvature of varifocal lens was varied by different current driving so that the focal length can be easily changed. Thus, we can quickly measure the distance between the sensor head and targets by detecting the reflective power according to the principle of confocal laser. This rainbow laser can operate at four different wavelengths. The laser beams with different colors can be used to measure the dispersion of varifocal lens. The range of measuring displacement with 20X objective lens in this displacement sensor is from 4.9mm to 5.9mm. The FWHM resolution of displacement is about 70μm. The step-height aluminate plate was measured by this system and the error of measuring distance is less than 35μm (0.75%).