Giraffes have very long necks primarily to help them reach leaves high up in trees, especially acacia trees, allowing them to access food sources that other herbivores cannot reach. This gives them a feeding advantage in their environment. Additionally, long necks are used by males during "necking" battles to compete for mates, so it also plays a role in mating and social dominance.