The density of a substance depends on how many particles there are in each cubic metre and on how closely they are packed. The particles themselves do not change, but the space between them does.
In a solid the particles are closely packed together, touching or almost touching. In a liquid the particles are also close together. So solids and liquids have a high density, and a solid is usually slightly denser than the same substance as a liquid. Water has a density of about 1000 kg/m3.
In a gas the particles are very far apart. There are fewer particles in each cubic metre, so a gas has a low density. Air has a density of about 1.2 kg/m3, so a cubic metre of liquid contains many more particles than a cubic metre of gas.
When a liquid boils to form a gas, the mass stays the same, but the volume increases a lot as the particles spread out. Since density = mass ÷ volume, the density decreases.