Costs of reproduction should depend on resource availability and on reproductive effort, which in turn may depend on traits influencing reproductive success. Therefore, variation in both habitat quality and reproductive traits should be considered when assessing reproductive costs. We investigated the effect of habitat quality and floral display on the costs of reproduction in the perennial herb Primula farinosa. In the study area, P. farinosa occurs in habitats that differ in water availability, which strongly influences plant performance. Furthermore, it displays a scape length dimorphism, with two distinct scape morphs differing in attractiveness to pollinators and reproductive success. To test the hypothesis that the cost of fruit production is higher in the long‐scaped than in the short‐scaped morph, and depends on water availability, we manipulated reproductive investment in eight P. farinosa populations along a gradient of soil moisture. Fruit set was higher in long‐scaped individuals, and prevention of fruit set increased flower production in the following year among long‐scaped, but not among short‐scaped plants. Furthermore, costs of fruit production were evident at low and high moisture levels but not at intermediate levels. The results demonstrate an association between a genetically determined difference in floral display and cost of reproduction, and suggest that costs of reproduction are non‐linearly related to water availability. They thus indicate links between the evolution of plant reproductive traits and plant life histories, and between habitat quality and optimal life history.