Mg-doped CdS samples were deposited via chemical bath deposition onto fluorine-doped tin oxide slides with varying levels of Mg-doping. Structural analysis revealed improved crystal quality in CdS films upon Mg incorporation. Morphological examinations indicated a reduction in grain size alongside appearance of smooth, void-free surfaces particularly evident at 3 % Mg-doping. Mg-doping also resulted in enhanced transparency of CdS films, notably at 3 % and 5 % within the visible spectrum. Efficient exciton dissociation was observed in hybrid solar cells based on 1 % and 3 % Mg-doped CdS, as evidenced by photoluminescence. Top-performing solar cell achieved an efficiency of 0.220 %, nearly seven times that of control device. 5 % Mg-doped CdS-based photodetectors exhibited favorable photosensing characteristics: a responsivity of 0.011 A/W, detectivity of 4.4 × 108 Jones, external quantum efficiency of 3.1 %, and rise/decay times of 26/25 ms at zero bias. These findings underscore beneficial effects of Mg-doping on both hybrid solar cell and self-driven photodetector performance.