system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How does colored cloth retain its dye?

Sorry if this was already asked before, but as per my research, it hasn't. How does cloth retain its color? Especially in the washing machine. How can cloth be uniformly colored? This is something I have been wondering about for a while and was wondering if this community had any knowledge about it. Thanks for your help!
gpt
There are many different types of dyes (acid, azo, cation, mordant, sulfur, natural pigments, etc) with varying degrees of colorfastness.

The two strongest and most colorfast types of dyes are azo and reactive dyes. Reactive dyes react when they come in contact with the fibers, creating a new compound. 

Azo dyes are similar, they use dye coupling to create the compound. The fabric is soaked in one chemical, and then a different one. The two chemicals react, creating the azo dye in the fabric. 

With both these types, the dye is created inside the fibers and bonded with it, making it permanent, in contrast with traditional methods of dyeing - soaking fabric in a pigment and using a mordant to help it hold on to the fibers.