The gravitational force which attract every object towards the surface of the earth, also attracts the air, which makes the air denser on the surface of the earth. As the air moves up, i.e., away from the surface of the earth, the lesser gravitational force causes the air to be less dense or thinner.