We investigate how high school gender composition affects students’ participation in STEM at college. Using Danish administrative data, we exploit idiosyncratic within-school variation in gender composition. We find that having a larger proportion of female peers reduces women’s probability of enrolling in and graduating from STEM programs. Men’s STEM participation increases with more female peers present. In the long run, women exposed to more female peers are less likely to work in STEM occupations, earn less, and have more children. Our findings show that the school peer environment has lasting effects on occupational sorting, the gender wage gap, and fertility.