In this work, Mg-doped CdS prepared at different concentrations of Mg were composited with polyvinyl alcohol (PVA) for functionalization in photocatalytic process. These nanocomposites films were characterized using different physicochemical techniques. The cubic structure identification of all the nanocomposites films was carried out by the X-ray diffraction, chemical state of the elements was determined from XPS analysis, the average particle size of samples was increased gradually with increasing concentration of Mg. FTIR spectra established the presence of stretching bond of CdS and PVA. The FESEM results depicted that the grown films were homogeneous. The optical properties of the composites examined by UV–Vis diffuse reflectance spectra show the band gap of CdS/PVA nanocomposite film decreases from 2.48 to 2.38 eV with increasing concentration of Mg. Photoluminescence spectrum shows a reduction in intensity due to the presence of low recombination rate of electron and hole pair. The synthesized photocatalyst demonstrated the superior visible light photocatalytic degradation of methylene blue (MB). The 5 mol% Mg-doped CdS–PVA nanocomposite film exhibited uppermost degradation of MB within 90 min. Therefore, the 5 mol% Mg-doped CdS–PVA nanocomposite has a remarkable enhancement in the degradation of pollutants under irradiation of visible light.