Undoped and Mg-doped ZnO thin films were deposited on Si(111) and quartz substrates by using the sol-gel method.Microstructure,surface topography and water contact angle of the thin films have been measured by X-ray diffraction(XRD),an atomic force microscope(AFM) and water contact angle apparatus,respectively. The XRD results show that all the thin films are polycrystalline with a hexagonal structure and have a preferred orientation along the c-axis perpendicular to the substrate.With the increase of Mg concentration,the RMS roughness increases from 2.14 to 9.56 nm and the contact angle of the un-irradiated thin films decreases from 89°to 82°. The wetting behavior of the resulting films can be reversibly switched from hydrophobic to hydrophilic,through alternation of UV illumination and dark storage.The light-induced efficiency of the thin films increases with the increase of Mg concentration.