A detergent is a made up of two parts: a long hydrocarbon part and a short ionic part containing - COONa+ group. The long hydrocarbon chain is hydrophobic, so the hydrocarbon part of the detergent molecule is insoluble in water but soluble in oil and grease. The ionic part of the detergent molecule is hydrophilic so it is soluble in water but insoluble in oil and grease. When the detergent is added to dirty clothes, which contains grease and oily substances, the greasy and oily dirt particles attach themselves to the hydrocarbon part and ionic part remains attached to the water. When the dirty clothes are agitated in a detergent solution, the dirt particles attached to the hydrocarbon part molecule get washed away in water and the clothes get cleaned.
Cleansing action of detergents in hard water: Synthetic detergents can lather well even in hard water because they do not form insoluble calcium or magnesium salts on reacting with the calcium and magnesium ions present in the hard water. Whereas when we talk about soaps, they are not suitable for hard water as they form insoluble calcium or magnesium salts on reacting with the calcium and magnesium ions present in the hard water.