Thank you for reaching out to us.
The Talmud (Shabbat 13b) refers to the shivah neki’im as “white days” (yemei libun). Shulchan Aruch Yoreh Deah 196:3 mandates wearing clean undergarments during the shivah neki’im. Rema there writes that the custom is to wear whites, but that in a pressing situation, a clean undergarment will do. Gra comments there that this was hinted at in the Talmud. Torat HaShlamim there notes that a colored undergarment that would affect analysis of the color of a stain would not be acceptable, as a matter of basic halacha.
In practice, white undergarments during the clean days are widely considered a binding custom, with clean undergarments acceptable in a pressing situation (or after the fact). That is to say, whites are not an absolute halachic requirement, but have become the halachic standard in practice.
Please let us know if we can be of further assistance.