Detergents contain surfactants and enzymes that pull dirt and oil away from fabrics, according to About.com Chemistry. The molecular structure of a surfactant is such that one part of the molecule is magnetized to grease and dirt, while the other side of the molecule is magnetized to water. When surfactants are agitated in the wash cycle, they form a molecular bond with dirt, pulling it out of material.
Modern detergents contain a variety of surfactants, so they work in different ways. For example, oxidizers use the oxygen molecule in water to produce a chemical reaction and whiten material. Detergents include water softeners, as many surfactants are more effective in soft water, which has a lower mineral content. Additional enzymes also draw fats and oils out of material. The enzymes protease and lipase are attracted to protein and fats. Amylase works on starches that are present in dirt. Enzymes use a molecular process to dissolve fats, proteins and starches so that surfactants can more effectively attach to these cells.
Detergents work on hard surfaces in the same way. These high-powered ingredients work together to isolate dirt and grease. Rinsing is the final step when using detergents. Whether these molecules are rinsed in a washing machine or on a hard surface, they adhere to clean water and are easily removed.