There are a few factors that contribute to temperatures being colder at higher altitudes.
Air is thinner, or less dense, at higher altitudes because of lower air pressure. Gases at lower pressures are cooler than gases at a higher pressure. Higher density items, like solids, retain heat better than lower density items, like liquids and gases. This explains the main reason why it is warmer near the surface of the Earth. Although some believe that being at a higher altitude means being closer to the Sun and therefore warmer, it is actually the surface of the Earth, warmed by the Sun, which provides the higher temperature at a lower altitude.
(see Layers of the Atmosphere)Tags: science