A facile preparation and structural, optical and electrical characterization of undoped and Y-doped CdS thin films are demonstrated through spray pyrolysis changing doping concentration of yttrium atoms in CdS structure. X-ray diffraction pattern displays that CdS samples have polycrystalline hexagonal phase and as they are doped by various amounts of Y atoms, a fluctuation is observed in the preferential orientation. Scanning electron microscopy results show that compact and smooth surface morphology in addition to a slight reduction in grain size are obtained with increasing Y-doping up to 5%. Transparency of CdS thin films are noticeably enhanced by doping of 1% Y atoms. However, further increase of Y-doping towards 5% causes less transparent CdS films due to deterioration of crystal quality. Tauc analysis indicates presence of two direct bandgaps for each sample owing to spin–orbit splitting of valence band of CdS. CdS films have bandgaps of 2.48 eV (Eg1) and 2.85 eV (Eg2). Whereas Eg1 value decreases to 2.46 for 5% Y-doping, Eg2 value increases to 2.92 eV for the same Y-doping concentration. Photoluminescence data show that an obvious red shift is observed for blue band regardless of Y-doping concentration. 3% Y-doped CdS thin films display the best carrier density of 4.37 × 1014 cm−3 and resistivity of 3.78 × 103 Ω.cm, which originate from substitutional incorporation of Y3+ ions at Cd2+ ions. Therefore, it can be stated that Y-doped CdS thin films exhibit better electrical and optical properties that are of vital importance in thin film-based solar cells as a window layer.