1 If different genotypes have different relative fitnesses in different habitats, genetic diversity may be maintained in local populations by habitat selection. The spatial structuring of genetic variation within plant populations will thus be associated with habitat variation and reflect niche differentiation. However, the spatial effects of inbreeding and restricted gene flow must be accounted for before genotype-habitat associations can be interpreted in terms of habitat selection and niche differentiation. 2 We studied the relationship between allozyme frequencies and habitat variation in the outbreeding, wind-pollinated and widely distributed grass, Festuca ovina on the Baltic island of Oland. The 'alvar' grasslands occupied by F. ovina on Oland are characterized by a complex mosaic of habitat variation, and we sampled individuals from six habitat types at each of four sites. Generalized linear models were used to explore the associations between allozyme frequencies and habitat type. The sampling strategy and statistical analyses were designed so as to exclude the effects of purely spatial variation. 3 The analyses revealed significant associations between allozyme frequencies and orthogonal gradients of grassland habitat variation at all four of the enzyme loci studied in F. ovina. 4 The association between allele frequencies and habitat variation are interpreted as the result of either direct or indirect selection on the enzyme loci that were studied. The among-habitat component of genetic variation thus corresponds to niche diversification and our results support the hypothesis that niche variation may contribute to the maintenance of genetic polymorphism within populations of F. ovina.