ZnO:Mg thin films with different amounts of Mg were deposited on a glass substrate using the spray pyrolysis technique. The structural, optical and antibacterial properties of the films were studied as a function of the dopant concentration. The ZnO:Mg films were characterized using methods such as x-ray diffractometry, scanning electron microscopy, scanning tunneling microscopy and UV-Vis spectroscopy. The samples display hexagonal wurtzite structure, with no secondary phase. Morphological studies indicated the deposition of a uniform film, and particle size decreases with Mg doping. Optical studies revealed that the optical band gap and optical transmittance increase with Mg concentration. The antibacterial activities of the samples against Escherichia coli (gram-negative) cultures were tested by the drop test method, which shows that Mg doping increases antibacterial activities of thin films.