Abstract: Rapid industrialization and urbanization have led to the most serious habitat degradation in China, especially in the loess hilly area of the Yellow River Basin, where the ecological environment is relatively fragile. The contradiction between economic development and ecological environment protection has aroused widespread concern. In this study, we used the habitat quality of Integrated Valuation of Ecosystem Services and Tradeoffs (InVEST-HQ) model at different scales to evaluate the dynamic evolution characteristics of habitat quality in Lanzhou City, Gansu Province of China. The spatiotemporal variations of habitat quality were analyzed by spatial autocorrelation. A Geographical Detector (Geodetector) model was used to explore the driving factors that influencing the spatial differentiation of habitat quality, including natural factors, socio-economic factors, and ecological protection factors. The results showed that the habitat quality index of Lanzhou City decreased from 0.4638 to 0.4548 during 2000–2018. The areas with reduced the habitat quality index were mainly located in the Yellow River Basin and Qinwangchuan Basin, where are the main urban areas and the new economic development areas, respectively. The spatial distribution of habitat quality presented a trend of high in the surrounding areas and low in the middle, and showed a significant positive spatial autocorrelation. With the increase of study scale, the spatial distribution of habitat quality changed from concentrated to dispersed. The spatial differentiation of habitat quality in the study area was the result of multiple factors. Among them, topographic relief and slope were the key factors. The synergistic enhancement among these driving factors intensified the spatial differentiation of habitat quality. The findings of this study can provide a scientific basis for land resources utilization and ecosystem restoration in the arid and semi-arid land.