It has been known for hundreds of years that alkali solutions (solutions with a high pH, the opposite of acids) remove dirt from clothing. This is why lye was once used as a detergent. Most of today’s laundry detergents are anionic surfactants that become alkaline in wash water. A surfactant is something that can dissolve (or dissolve in) two dissimilar substances – like oil and water, for example. An anion is a negatively-charged particle. Since dirt is largely positively-charged, the negatively-charged anions from the detergent attach to it, and then the complex dissolves in the wash water, away from the clothing.
Hard water contains a lot of positively-charged calcium and magnesium ions. Remember that dirt is also positively-charged. This means that the detergent must chelate, or “lock up” the calcium and magnesium ions before it can affectively clean. This explains why hard water requires more soap for cleaning. The chelating agents in detergent combined with calcium and magnesium ions often appear as soap scum. Animal fibers (silk and wool) are not affected by alkaline wash solutions – this is why they need dry-cleaning. Some non-ionic (neutral) detergents may be used for these fabrics.
Fabric softeners are positively-charged surfactants. They are acidic in water. They alter the surface of the fibers so they feel soft to the touch. They also may remove some residual soap and dirt particles from the fabric.