Smart windows with high near-infrared (NIR) light shielding and controllable visible light transmittance are highly sought after for cooling energy saving in buildings. Herein we present a rationally designed spectrally selective smart window which is capable of shielding 96.2% of the NIR irradiation from 800 nm to 2500 nm and at the same time permitting acceptable visible light (78.2% before and 45.3% after its optical switching) for indoor daylighting. The smart window synergistically integrates the highly selective and effective NIR absorption based photothermal conversion of cesium tungsten bronze (CsxWO3) with the transparent thermo-responsive poly(N-isopropyl acrylamide) microgel-polyacrylamide (PAM-PNIPAM) hydrogel. The optical switching of the smart window is a direct result of the phase transition of PAM-PNIPAM hydrogel which in turn is induced by the photothermal effect of CsxWO3 under sunlight irradiation. The smart window exhibits fast optical switching, shows a long-term operational stability, and can be made highly flexible. Under the experimental conditions in this work, the indoor temperature with the smart window is ~21 °C lower than that with regular single-layered glass window under one sun irradiation. The smart window design in this work is meaningful for further development of effective smart windows for energy saving in the build environment.