Zn(1–x)MgxO thin films with various concentrations of magnesium were deposited using the spray pyrolysis method. The transmittance spectra recorded for all films exhibit maxima exceeding 90%. The band gap energy of the films with wurtzite structure increases from 3.22 up to 3.60 eV by incorporating Mg into ZnO. However, when the atomic ratio of Mg exceeded 0.4, a second crystalline phase (assigned to cubic MgO) became discernable in XRD patterns, a compressive strain was observed in the wurtzite lattice, and crystallite sizes decreased significantly. In accordance with these observations, finer grains with a pronounced columnar growth were observed in 3D AFM representations and the surface roughness decreases significantly. Finally, selective etching in water yields to porous films with a great surface-to-volume ratio, a lower refractive index and a better light transmission. These porous films with tunable band gap seem to be excellent candidates to various interesting applications.