Vanadium dioxide (VO2) is a promising thermochromic material for smart windows. However, the relatively high phase transition temperature (Tt) and low visible transmittance (Tlum) constrain its practical application. Cationic co-doping offers an effective strategy to optimize the optical switching properties near room temperature. In this line, herein, the W-Mg co-doped VO2 films were synthesized by a solution and annealing method from W-Mg co-doped ammonium citrato-oxovanadate (IV). The synergistic effect of W-Mg co-doping improves the performance of VO2 films with Tt of 42.6 °C, Tlum of 59.0 % and solar energy modulation of 12.8 %. By changing the amounts of Mg, the W-Mg co-doped VO2 film maintains the low Tt of W-VO2 film and meanwhile possesses higher Tlum, which is attributed to the band gap structure change induced by the W-Mg co-doping. The excellent optical, thermochromic and thermal insulation performances confirm that our research could provide guidance for advancing the application of VO2 in smart window fields.