Thin films of pure ZnO and Mg-doped ZnO(MgZnO)with different Mg concentrations were prepared by magnetron sputtering.The dependence of the electrical,optical and gas sensing properties and microstructure of the thin films upon Mg doping amount was investigated.The effects of temperature and the concentration of gases on the gas sensing properties of the thin films were studied,and the room temperature gas sensing characteristics of the MgZnO thin film with 10%Mg doping amount(mass fraction)were carefully investigated.The results showed that all the fabricated thin films had hexagonal wurtzite-type crystal structure with highly c-axis preferred orientation along the(002)plane.The MgZnO thin film with 10%Mg doping demonstrated the best crystal quality,microstructure,and optical properties.Meanwhile,it was observed that the MgZnO thin film with 10%Mg showed better gas response than other thin films,and higher response towards ammonia compared to other target gases.The gas response of the 10%MgZnO thin film for 50 cm3∙m-3 ammonia was 44.62%,and only slightly decreased to 42.02%after 180 days at room temperature.