Soil fungi are involved in the decomposition of organic matter, alter soil structure and physicochemical properties and drive the material cycle and energy flow in terrestrial ecosystems. Grazing exclusion is one of the most common measures to restore degraded grasslands worldwide. However, changes in soil fungal community characteristics during grazing exclusion in different types of grasslands are unknown, and in particular, there is a lack of experimental evidence on the effects of grassland type and grazing exclusion on soil fungal diversity. Here, we investigate the effects of a 9-year grazing exclusion on soil properties, fungal community composition and diversity in three grassland types (Temperate desert, Temperate steppe and Mountain meadow). The results showed that soil fungal community composition differed between grassland types, and that grazing exclusion, grassland type and the interaction between the two did not significantly affect soil fungal α-diversity and composition, but significantly altered fungal β-diversity. Overall, our results highlight the importance of soil nutrient content on fungal diversity, particularly soil total nitrogen, total phosphorus and organic carbon, and provide key evidence to reveal the mechanisms by which soil fungi respond to grazing exclusion in different grassland types.