The synthesis of the photochromic YHO films is based on the oxidation of deposited yttrium hydride in ambient conditions. The actual state of the films during the deposition process, which is influenced by the deposition pressure and the oxidation caused by the residual gases, is not completely known. We report on the YHxOy thin films deposited by reactive pulsed-DC magnetron sputtering. Since the visible light transmittance is closely related to the phase and chemical composition of the films, in situ transmittance measurements during and after deposition are performed to investigate the oxidation in more detail. Spectroscopic ellipsometry is used to determine the optical constants of YHxOy throughout the film thickness. In order to obtain metallic YH2-x films with a low oxygen content, a low sputtering pressure (<1 Pa) is required, otherwise the films are already partially transparent during the deposition. The oxidation is faster when higher deposition pressures are used. This is due to the more porous growth of the microstructure at higher pressures that is observed at the surface and cross-section images of the films. The films exhibit a refractive index gradient perpendicular to the substrate surface, which is related to the porosity and variation of the chemical composition.