A hat is a head covering.
It can be worn for protection against the elements, for ceremonial reason, religious reasons, for safety, or as a fashion accessory. In the past, hats were an indicator of social status. In the military, they may denote nationality, branch of service, rank and/or regiment.

Ancient Greek statue of a lady with blue and gilt garment, a fan and a sun hat, from Tanagra, circa 325-300 BC.

Hermes wearing a petasos hat. (Ancient Greek Attic red-figure krater, circa 380–370 BC.)
New York City, 1918: A large crowd of people, almost all wearing hats.