The Martian atmosphere is an extremely thin sheet of gas, principally carbon dioxide, that extends from the surface of Mars to the edge of space. The Martian atmosphere is less dense than the Earth's atmosphere, but there are many similarities.
Gravity holds the atmosphere to the Martian surface.
And within the atmosphere, very complex chemical, thermodynamic , and fluid dynamics effects occur. These variations extend upward from the surface of Mars. The sun heats the surface, and some of this heat goes into heating the gas near the surface. The heated gas is then diffused or convected up through the atmosphere. Thus, the gas temperature will be highest near the surface and decreases as altitude increases.