Conspicuous plumage patches have evolved in birds as conspecific signals for mate attraction and assessment, intersexual competition or to signal alarm. Signals may alternatively be directed at potential predators to discourage pursuit. Rails (Family Rallidae) are ground-dwelling birds, many of which inhabit wetlands, while others occur in forests and grasslands. They are renown for their secretive nature and the tendency to flick their tails when observed. This behavior is more conspicuous in species with white undertail coverts that contrast sharply with darker body plumage. Using species comparisons and controlling for phylogeny, we investigated four hypotheses for the evolution of white undertail coverts in rails. We found little support for the hypothesis that white tails are sexually selected: white tails were not more common in species with polygamous as opposed to monogamous mating systems, species with sexual dimorphism, nor species that display their tails in courtship. Nor did our results support the hypothesis that white tail plumage evolved for intersexual competition during territorial interactions. Instead, we found that species that flock for at least part of the year and species found in open as opposed to concealing habitats were significantly more likely to have white undertail coverts. Rail species inhabiting concealing habitats are less commonly gregarious and more likely selected for crypsis. Using phylogenetically-controlled statistical inference we found that adaptation to open wetland habitats significantly precedes the evolution of white undertails, whereas gregariousness likely evolved later in some lineages. The inferred order of trait evolution suggests that this plumage characteristic could have been selected primarily for enhancement of an anti-predator signal rather than a social signal for conspecifics.