Polarized (sub)millimetre emission from dust grains in circumstellar disks was initially thought to be because of grains aligned with the magnetic field1,2. However, higher-resolution multi-wavelength observations3–5 and improved models6–10 found that this polarization is dominated by self-scattering at shorter wavelengths (for example, 870 µm) and by grains aligned with something other than magnetic fields at longer wavelengths (for example, 3 mm). Nevertheless, the polarization signal is expected to depend on the underlying substructure11–13, and observations until now have been unable to resolve polarization in multiple rings and gaps. HL Tau, a protoplanetary disk located 147.3 ± 0.5 pc away14, is the brightest class I or class II disk at millimetre–submillimetre wavelengths. Here we show deep, high-resolution polarization observations of HL Tau at 870 µm, resolving polarization in both the rings and the gaps. We find that the gaps have polarization angles with a notable azimuthal component and a higher polarization fraction than the rings. Our models show that the disk polarization is due to both scattering and emission from the aligned effectively prolate grains. The intrinsic polarization of aligned dust grains is probably more than 10%, which is much higher than that expected in low-resolution observations (about 1%). Asymmetries and dust features that are not seen in non-polarimetric observations are seen in the polarization observations. Deep, high-resolution polarization observations of HL Tau at 870 µm show gaps that have polarization angles with a notable azimuthal component and a higher polarization fraction than the rings.