Polarization and phase devices for terahertz waves have important applications in terahertz detection, imaging, communication, etc. Spatially variable metal gratings can be used for broad-spectrum, miniaturized, and low-cost terahertz polarization and phase modulation devices. Based on the effective dielectric constant and the theory of light propagation in multilayer media, we obtain the relationship between the transmittance and extinction ratio and the parameters such as the duty cycle of the metal grating, the frequency of the incident terahertz wave, the angle of incidence, the thickness of the metal grating, the refractive index of the substrate, and the thickness of the substrate. We propose a method of designing a spatially variable metal grating located on a transparent substrate. The designed spatially variable metal grating is also used to modulate the terahertz spatial polarization and phase to generate terahertz optical fields whose polarization and phase change simultaneously in space, such as azimuthally vector vortex terahertz optical fields, radially vector vortex terahertz optical fields, and so on. This will have important applications in terahertz time-domain spectroscopic detection, terahertz time-domain spectroscopic imaging, terahertz time-domain near-field microscopic imaging, terahertz communication, and so on.