Density is a measure of how much mass is contained in a given amount of space (volume).
The number of particles per unit volume of a substance is the maximum in solids, hence, solids have more density than liquids and gases.
Solids have a definite shape and size, as the particles are very closely packed with no space in between them. Hence, the density of solids is the maximum.
Particles in a liquid have more space between them and there are fewer particles per unit volume. So, the density of liquids is less than that of solids.
Comparatively, gases have the least density because the space between the particles is the maximum. Their kinetic energy is more than that of liquids. Hence, gases do not have a definite shape and volume.