Dogs wag their tails when they are happy as a way to communicate their emotions and to express joy and excitement. Tail wagging is a form of body language for dogs, and it is a way for them to show their positive feelings towards humans and other animals.