The relationship between biodiversity and productivity has emerged as a central theme in ecology. Mechanistic explanations for this relationship suggest that the role organisms play in the ecosystem (i.e., niches or functional traits) is a better predictor of ecosystem stability and productivity than taxonomic richness. Here, we tested the capacity of functional diversity in nitrogen uptake in experimental microalgal communities to predict the complementarity effect (CE) and selection effect (SE) of biodiversity on productivity. We grew five algal species as monocultures and as polycultures in pairwise combinations in homogeneous (ammonium, nitrate, or urea alone) and heterogeneous nitrogen (mixed nitrogen) environments to determine whether complementarity between species may be enhanced in heterogeneous environments. We show that the positive diversity effects on productivity in heterogeneous environments resulted from complementarity effects with no positive contribution by species‐specific SEs. Positive biodiversity effects in homogeneous environments, when present (nitrate and urea treatments but not ammonium), were driven both by CE and SE. Our results suggest that functional diversity increases species complementarity and productivity mainly in heterogeneous resource environments. These results provide evidence that the positive effect of functional diversity on community productivity depends on the diversity of resources present in the environment.