A hat is sometimes part of a formal outfit such as a suit.