Context. We study how the electromagnetic interaction between the monomers in aggregates affects the polarization of cosmic dust. Aims. We aim to show that the electromagnetic interaction depends on the porosity and composition of the aggregates and contributes significantly to the spectral gradient of polarization (polarimetric color). The results may explain the observations of some comets that demonstrated atypical negative polarimetric color in the visible and also a reverse of the positive polarimetric color to the negative one in the near-infrared. Methods. We performed computer simulations of the light scattering by aggregates consisting of spheres made of a variety of materials: transparent, absorptive, and the material similar to that of the dust in comet Halley. We studied how the number of monomers covered by the electromagnetic wave at a single period (on the light path equal to one wavelength) affects their interaction by considering linear clusters of 2 and 10 monomers of radius of 0.1 μm. Results. Electromagnetic interaction between the monomers in aggregates depolarizes the light. The interaction becomes stronger if more monomers are covered by the electromagnetic wave at a single period. Thus, the porosity of aggregates influences their polarization. The electromagnetic interaction also depends on composition and is stronger for transparent materials. Conclusions. Electromagnetic interaction between the monomers in aggregates may explain why the polarimetric color of comet dust decreases as observations move from the visible to the near-infrared since a longer wavelength covers more monomers. It may also explain why some comets exhibit negative polarimetric color even in the visible; these comets may have more compact dust. Strong electromagnetic interaction resulted either from compactness or transparency of the material can explain the negative polarimetric color of interplanetary dust and debris disks and contribute to the polarization of asteroids. In general, the spectral dependence of polarization is a promising tool for studying the properties of cosmic dust particles, particularly their porosity.