A detergent removes organic and oily stains from clothes by means of surfactants, which are one of detergent's main ingredients. Surfactants interact with water and oil differently, dislodging oily stains from clothes when they come in contact with water in a washing machine.
The word "surfactant" stands for surface-active agent, a name derived from its chemical structure. The tail of a surfactant molecule is attracted to dirt and grease, whereas the head of the molecule is attracted to water. Once a piece of clothing comes into contact with water containing detergents, one end of the surfactant molecule attaches itself to grease, while the other attaches itself to water. As mechanical energy is applied to a piece of clothing, as when it's tumbled in a washing machine, the molecules assume the shape of tiny spheres that contain the grease, and they are subsequently rinsed away as the water gets drained.
In addition to surfactants, modern detergents contain enzymes, blue dyes and bleaches. The enzymes degrade protein-based stains, while bleaches increase the power of the cleaning agents and remove the color from the stains. Blue dyes are added to detergents to prevent clothes from turning yellow. Detergents are typically made from oleochemicals, which are derived from animals and plants, and from petrochemicals. They also contain oxidizers and alkali.