The electronic properties and optical activities of C-doped cubic SrTiO3 in perovskite structure are studied by first-principles calculation. The calculated formation energies show that the substitutional C impurity is preferentially occupied at the Ti site. For C@O, the C impurity introduces spin-polarized gap states, and the associated electron excitations among the valence band, the conduction band and the gap states produce various visible-light absorption thresholds. For C@Ti, some C gap states of s-character appear near the bottom of the conduction band, which result in the lowered optical transition energy and thus the visible light absorption as observed in the experiment