Whether sexual or viability selection drives the evolution of ornamental traits is often unclear because current function does not clarify evolutionary history, particularly when the ornamentation is a modified version of the functional traits. Here, using a phylogenetic comparative approach, we studied how deeply forked tails-a classic example of sexually selected traits that might also be a mechanical device for enhancing aerodynamic ability-evolved in two groups of aerial foragers, swallows (family: Hirundinidae) and swifts (family: Apodidae). Although apparent fork depth, the target of sexual selection, increases with increasing outermost tail feather length, fork depth can also increase with decreasing central tail feather length, which impairs the lift generated by the tail. Thus, we predicted that sexual selection, but not viability selection, should favour the evolution of short central tail feathers in species with deeply forked tails, particularly in swifts, which are less reliant on the lift generated by their tail than in swallows. We found support for these predictions because central tail feather length decreased with increasing tail fork depth, particularly in swifts. Instead, the increase in outermost tail feather length per unit tail fork depth was higher in swallows than in swifts, indicating that a similar sexual ornamentation (i.e. forked tails) differently evolved in these two aerial insectivores perhaps due to the differential cost of ornamentation. We also found support for an optical illusion that changes the relative importance of central and outermost tail feather length in sexual selection.