While we can’t see them, the gas and vapour molecules making up the atmosphere all have mass, and as such all feel the gravitational pull of the Earth. They could still escape if they had enough energy – for example, if the Earth was closer to the Sun, and thus hotter. Fortunately, however, our planet has just the right mass and distance from the Sun to avoid that.