The electronic structures, dipole moment and optical properties of C–N-doped and C–N-codoped anatase titanium dioxide (TiO2) are studied using the plane-wave ultrasoft pseudopotential method of density functional theory (DFT). The results revealed that the absorption coefficients of pure TiO2 and N-doped TiO2 are consistent with experimental values in the visible-light region. The bands originating from C/N-2p states lie in the band gap of doped TiO2. A visible-light absorption edge red-shift can be observed. The atomic charges have changed, resulting in devation of the center of gravity of the negative electric charge from the positive electric charge in the super-cell, and their dipole moment would not be zero. The dipole moment has large influence on the optical responses in the visible region of TiO2. Because of the small distance (0.531 nm) between C and N atoms, the covalent bond component was easily enhanced between C atom and adjacent O atom, the covalent bonds making it more difficult for the carrier transfer. Moreover, its optical absorption coefficient is going to reduce in the visible-light region. Under the condition of the larger distance (0.691 nm) between C and N atoms, their interaction can be reduced, which is beneficial to electrons transition; as a result, a significant improvement of the photocatalytic activity of TiO2 has been found under the visible-light irradiation.