Tailoring optical bandgap of ZnO nanostructured thin films doped with different elements facilitates potential material for photonic applications. Different methods of fabrication process result in different optical and structural properties for the same amount of Mg content. Therefore, details investigation of structural and optical parameters, and their correlation need to be revealed to utilize the fabricated thin films. In this work, Mg-doped ZnO thin film of 200nm thickness was fabricated by sol-gel spin coating method on a glass substrate for four different Mg content levels. Multiple layers were deposited by a spin coater to increase the film thickness. The prepared thin films were characterized by SEM, XRD, EDS, and UV–Vis spectroscopy. The spectroscopic analysis showed a uniform crystalline nanostructured surface with less structural defects, enhanced transmittance, and higher optical bandgap than that of pure ZnO nanostructured thin film. Change of Mg content from 2% to 8% facilitated tuning of bandgap in the range of 3.30–3.39eV. Changing trend of structural and optical parameters with Mg content showed non-linear, non-monotonic relation. In-depth analysis of structural and optical properties provides crucial information to form a better view about bandgap dependency on structural parameters.