Density functional calculations are performed to investigate the structural, electronic, and optical properties of Zn1-xMgxS (0 ≤ x ≤ 1). In the present DFT calculations, we used modified Becke-Johnson potential in the exchange and correlation energy, which is effective for the treatment of the d-orbitals. A structural phase transition from zinc-blende to rock-salt is observed at 73% magnesium, which is consistent with the experimental results. Furthermore, the alloy has direct band gap nature for the whole range of Mg concentration in the zinc-blende structure, while the band gap nature for the rock-salt phase is indirect. The zinc-blende crystal structure has many established applications in the UV optoelectronic devices, and therefore the maintenance of the compound in zinc-blende crystal structure for the maximum range of Mg-composition is highly desirable which is dependent on the composition rate, external environment, and thickness of the film. Keeping in view the importance of ZnMgS in UV optical devices, its optical properties like dielectric functions, refractive indices, reflectivity, and energy loss function are also investigated.