Here we establish that contrary to expectations, Caenorhabditis elegans nematode worms possess a color discrimination system despite lacking any opsin or other photoreceptor genes. We found that simulated daylight guides C. elegans foraging decisions with respect to harmful bacteria that secrete a blue pigment toxin. By absorbing yellow-orange light, this blue pigment toxin alters the color of light sensed by the worm, and thereby triggers an increase in avoidance of harmful bacteria. These studies thus establish the existence of a color detection system that is distinct from those of other animals. In addition, these studies reveal an unexpected contribution of microbial color display to visual ecology.