Titania is a widely used semiconductor due to its excellent optoelectronics and catalytic properties. Doping with other cations or anions by substitution of Ti or O is a common way to adjust the electronic structure of pristine TiO2. Here, using ab initio calculations at the Heyd-Scuseria-Ernzerhof (HSE06) level, the substitution energy, formation energy and electronic structures of anatase TiO2 doped with 40 kinds of elements including transition metals, alkali metals, alkaline earth metals, p-block metals, and nonmetals have been studied systematically. It is found that doping with most of these elements can narrow down the band gap of TiO2, while in some doped systems, a recombination center induced by intermediate bands is also observed. Besides, for transition metal-doped TiO2 systems, the electron spin state analysis of dopants and the doping level investigation reveal that a relatively high spin structure tends to be formed in Cr, Mn, Fe, Zn, Mo, Tc, Ru and Cd-doped TiO2, and the doping levels of 4d-orbital transition metals are generally higher than those of 3d-orbital transition metals.