To utilize visible light more efficiently in photocatalytic reactions, carbon-doped TiO2 (C−TiO2), nitrogen-doped TiO2 (N−TiO2), and carbon and nitrogen co-doped TiO2 (C−N−TiO2) nanoparticles with different nitrogen and carbon contents were prepared by a sol−gel method and characterized by X-ray diffraction (XRD), transmission electron microscopy (TEM), X-ray photoelectron spectroscopy (XPS), and UV−vis spectroscopy. XRD results showed that the doping of C and N atoms could suppress the crystal growth of TiO2, and the effect of C doping was more pronounced than that of N doping. XPS, UV−vis spectroscopy, and lattice parameter analysis revealed that N atoms could incorporate into the lattice of anatase through substituting the sites of oxygen atoms, while most C atoms could form a mixed layer of deposited active carbon and complex carbonate species at the surface of TiO2 nanoparticles. The photocatalytic activities of obtained C−TiO2, N−TiO2, and C−N−TiO2 samples with different C and N contents were evaluated by methylene blue degradation under visible light irradiation. It was found that C−N−TiO2 nanomaterials exhibited the highest photocatalytic activity, which could be assigned to the synergistic effect of doped C and N atoms.