In this study, pure and Mg doped CdO thin films were coated on glass substrate using a chemical bath deposition method. Adding different molar concentrations of magnesium (0, 2, 4, 6) % to the chemical bath solution and their effect on the structural and optical properties were studied. Oxidation of films was conducted at 573 K for 60 minutes in the presence of static air. The thin film properties were diagnosed with X-ray diffraction techniques and UV-VIS-spectrophotometer. The results of X-ray diffraction for the thin films showed that all prepared thin films have a faced-centered cubic crystal structure (FCC) with a preference for growth at level (111), and the synthetic coefficients calculated from the X-ray spectrum are affected with increasing Mg ratios in the chemical bath solution. The results of the optical tests showed that the absorption of the resulting thin films increases with increasing Mg ratios in the chemical bath solution, have a high absorption coefficient in the visible region of the electromagnetic spectrum, and the transmittance decreases with the increase of Mg in the chemical bath solution. The optical energy gap of the prepared thin films changes with increasing Mg doping rates and extends from (2.46) eV to (2.95) eV. The results showed a significant improvement in the structural and optical properties of Mg ion doped CdO films making it suitable for use in many photovoltaic applications such as reagents and solar cells.