Heavy metals in haze episode will continue to threaten the quality of public health around the world. In order to decrease the emission of heavy metals produced from coal burning, an online X-ray fluorescence (XRF) analyzer system, consisting of an XRF analyzer with data acquisition software and a laser rangefinder, was developed to carry out the measurement of heavy metals in pulverized coal. The XRF analyzer was mounted on a sled, which can effectively smooth the surface of pulverized coal and reduce the impact of surface roughness during online measurement. The laser rangefinder was mounted over the sled for measuring the distance between a pulverized coal sample and the analyzer. Several heavy metals and other elements in pulverized coal were online measured by the XRF analyzer directly above a conveyor belt. The limits of detection for Hg, Pb, Cr, Ti, Fe, and Ca by the analyzer were 44 ± 2, 34 ± 2, 17 ± 3, 41 ± 4, 19 ± 3, and 65 ± 2 mg·kg(-1), respectively. The relative standard deviation (%RSD) for the elements mentioned was less than 7.74%. By comparison with the results by inductively-coupled plasma mass spectrometry (ICP-MS), relative deviation (%D) of the online XRF analyzer was less than 10% for Cr, Ti, and Ca, in the range of 0.8-24.26% for Fe, and greater than 20% for Hg and Pb.