Quick, what's inside a can of hair spray? If your answer is, "well, hair spray, of course," you're only partly right. Whether it's hair spray or spray paint, anything that comes out of an aerosol can shares space with another substance.
That other substance is gas. Unlike solid and liquid particles that stick together, gas particles move around independently, pushing outward to expand and fill any open space. As a result, in the open air, gas exerts little pressure on the objects around it. But when enough gas is forced into a small space such as an aerosol can, its expansion-hungry particles apply a lot of pressure on whatever else is in the can. This is what forces hair spray out of the can when you press the nozzle.
Say you wanted to make a can of hair spray. First, pour in the liquid hair product, seal the can, and attach a nozzle with a tube running to the bottom. Then, pump in gas at high pressure. Exerting pressure, the gas pushes down on the liquid hair spray, forcing it up near the top of the tube where a closed valve blocks its escape. When you push the nozzle down it opens the valve, allowing the liquid to rush out in a fine spray.
So what's inside a can of hair spray? Now you know that it's more than just the stuff that holds your hair in place.