The invention relates to a preparation method for nitrogen, phosphorus and sulfur co-doped mesoporous carbon spheres. The method utilizes polyaniline doped organic acid-phytic acid as a carbon precursor, and uses nano silicon dioxide spheres as a template agent, and polyaniline, phytic acid and ammonium persulfate are simultaneously used as nitrogen, phosphorus and sulfur sources; and high-temperature carbonization is performed, a template substance is removed, and therefore the nitrogen, phosphorus and sulfur co-doped mesoporous carbon spheres are obtained. According to the method provided bythe invention, the prepared mesoporous carbon spheres have a unique pore structure, the high content of codoping of nitrogen, phosphorus and sulfur, and a high specific surface area; the preparationprocess is fast and simple, the structure is controllable, and the carbon spheres are suitable for mass production; and the prepared nitrogen, phosphorus and sulfur co-doped mesoporous carbon spherescan be widely used in the fields of supercapacitors, capacitive desalination, lithium ion batteries, sodium ion batteries and the like.