Abstract Anthropogenic habitat changes resulting from urban development have significantly altered plant habitats. Although urbanisation has created diverse habitat types, the effects of this diversity on plant trait diversification remain poorly understood. In this study, we established a common garden experiment using seeds from 23 Commelina communis populations inhabiting different habitat types, including rural agricultural lands, urban agricultural lands, parks and roadsides, along the urban–rural gradient of the Kyoto–Osaka–Kobe megacity in Japan. We assessed four abiotic factors, measured eight functional traits and biomass, and evaluated environmental differences and trait differentiation among rural and urban habitat types. Additionally, we conducted population genetic analysis to compare quantitative genetic trait differentiation ( Q ST ) with neutral genetic differentiation ( F ST ), aiming to uncover potential urban adaptive divergence. Urban habitats generally exhibited higher soil pH and land surface temperature owing to the increase in surrounding developed lands, with urban parks being more shaded and roadsides drier compared to rural habitats. Urban populations, particularly those from roadsides, exhibited distinct traits such as increased plant height, larger plant height/width ratio, fewer shoots and leaves and/or larger leaves compared to rural populations. Moreover, urban agricultural land populations displayed delayed flowering phenology relative to other urban populations. Higher land surface temperature was associated with increased plant heights and leaf sizes but reduced shoot numbers, while higher openness and/or soil pH promoted greater height/width ratios and increased leaf sizes. Flowering phenology was delayed under higher openness and surface temperature. The Q ST – F ST comparisons, alongside the relationships between traits and environmental factors, strongly suggest that local adaptation to hot, shaded and/or eutrophic urban environments has driven the observed trait divergence among various urban populations. Synthesis . Integrating Q ST – F ST comparisons with habitat environmental surveys and common garden experiments can provide new insights into the relative importance of local adaptation and neutral evolution in shaping trait responses in diverse urban habitats. Urban habitat diversity, which in turn provides environmental diversity, has driven adaptive trait divergence among rural and urban populations in flowering plants.