Detergent was first created in 1916 as a response to fat shortages caused by World War I. Constant improvements have been made in its cleaning power. A primary consideration for the past several decades is the environmental impact of detergent chemicals.
When a fat or oil is mixed with chemicals such as sodium or potassium hydroxide, it produces fatty acid salts -- also known as soap. The alkaline to acid, or base, scale runs from 1 to 14, with the alkaline compounds from 1 to 6 and base compounds 8 to 14. Compounds that are 7 are considered neutral. Sodium, potassium hydroxide or other substitute chemicals fall on the high side of the alkaline/acid measurement.
By definition this makes any compound derived from these chemicals an acid or base compound. Detergent merely replaces the fat with a synthetic surfactant, leaving the rest of the process virtually the same. Detergents are not quite 11 on the scale, with ammonia being a little under 12 and bleach a little over.
The compounds in detergent both wet the clothing and surround the oils and dirt on the clothing surface. This lifts the stains away from the surface and deposits them into the water. This process uses the portion of the detergent called the surfactant.