The non-random distribution of anopheline larvae in natural habitats suggests that gravid females discriminate between habitats of different quality. Whilst physical and chemical cues used by Culex and Aedes vector mosquitoes for selecting an oviposition site have been extensively studied, those for Anopheles remain poorly explored. Here the habitat selection by Anopheles gambiae sensu lato (s.l.), the principal African malaria vector, was investigated when presented with a choice of two infusions made from rabbit food pellets, or soil. Natural colonization and larval survival was evaluated in artificial ponds filled randomly with either infusion. Dual-choice, egg-count bioassays evaluated the responses of caged gravid females to (1) two- to six-day old infusions versus lake water; (2) autoclaved versus non-autoclaved soil infusions; and assessed (3) the olfactory memory of gravid females conditioned in pellet infusion as larvae. Wild Anopheles exclusively colonized ponds with soil infusion and avoided those with pellet infusion. When the individual infusions were tested in comparison with lake water, caged An. gambiae sensu stricto (s.s.) showed a dose response: females increasingly avoided the pellet infusion with increasing infusion age (six-day versus lake water: odds ratio (OR) 0.22; 95% confidence interval (CI) 0.1-0.5) and showed increasing preference to lay eggs as soil infusion age increased (six-day versus lake water: OR 2.1; 95% CI 1.4-3.3). Larvae survived in soil infusions equally well as in lake water but died in pellet infusions. Anopheles gambiae s.s. preferred to lay eggs in the non-autoclaved soil (OR 2.6; 95% CI 1.8-3.7) compared with autoclaved soil. There was no change in the avoidance of pellet infusion by individuals reared in the infusion compared with those reared in lake water. Wild and caged An. gambiae s.l. females discriminate between potential aquatic habitats for oviposition. These choices benefit the survival of the offspring. Although the study was not designed to distinguish between stimuli that acted over a distance or on contact, it could be demonstrated that the choice of habitat is mediated by chemical cues based on both preference and avoidance. These cues, if identified, might be developed for 'push-pull' strategies to improve malaria vector monitoring and control.