A series of photochromic sol-gel films are prepared through entrapping tungsten heteropolyoxometallates (PW12O403−, SiW12O404−) and molybdenum heteropolyoxometallate (PMo12O403−) into a kind of inorganic–organic matrix cohydrolyzed from tetraethylorthosilicate and 3-aminopropyltriethoxysilane. The films show reversible photochromicity. Irradiated with ultraviolet light, the transparent films change from colorless to blue. Then, bleaching occurs when the films are in contact with air or O2 in the dark. The Keggin-type polyanions interact with R–NH3+ cations strongly, and thus disperse uniformly in the sol-gel matrix, as proved by Fourier transform infrared spectra and x-ray diffraction. The molybdenum heteropolyoxometallate sol-gel film has higher photochromic efficiency and much slower bleaching than its counterparts of tungsten heteropolyoxometallate. A charge-transfer model which is supported by electron spin resonance and related literature [T. Yamase, Chem. Rev. 98, 307, (1998)] is put forth to explain the above experimental results.