Mg(2+) and Na(+) doped rutile TiO2 nanofibers have been prepared through in situ electrospinning technique and calcination with poly(vinyl pyrrolidone) (PVP) nanofibers as sacrificed template. The as-prepared composite nanofibers are spin-coated onto a ceramic substrate with three pairs of carbon interdigital electrodes to measure its humidity sensing behaviors. The product exhibits high-speed response (2s) and recovery (1s) for detecting moisture. Additionally, under UV irradiation, a water contact angle (theta) of nearly 0 degrees has been observed based on the product, providing our humidity sensor with the anti-fogged properties.