Why does a substance as a gas have a lower density than the same substance as a solid or liquid

When a substance changes from a solid or liquid phase to a gas phase, the molecules spread out and become more spread apart from each other. This increase in intermolecular distance results in a decrease in the density of the substance. In contrast, when a substance changes from a gas phase to a solid or liquid phase, the molecules come closer together, resulting in an increase in density. Therefore, a substance as a gas has a lower density than the same substance as a solid or liquid.