Both soap and detergent molecules have a hydrophilic (water-attracting) head and a hydrophobic (water-repelling) tail. The hydrophilic head allows the molecules to interact with water, while the hydrophobic tail interacts with oils and grease.