The density of a material depends on how closely its particles are packed. In a solid the particles are close together in a regular pattern and they vibrate about fixed positions. In a liquid the particles are also close together, but they are in a random arrangement and move past each other. In a gas the particles are far apart and move around quickly in random directions.
Solids and liquids have similar densities because their particles are both close together. A solid is usually the most dense state and a liquid is usually slightly less dense.
A gas has a very low density because its particles are far apart, so there are only a few particles in each unit of volume. When a liquid boils to form a gas, the mass stays the same but the particles spread out over a much larger volume, so the density decreases.