The heroes and villains in westerns had reliable looks
In old black & white westerns of the 1920s-40s, the heroes and the outlaws generally followed pretty standard looks. Our heroes would be in white hats, our villains in black hats. This is largely because of (geographically) western culture’s semiotic associations that the color white represents good while the color black represents evil. Also, white & black standout more in the colorless mediums of early movies and tv. The show Westworld carries this forward when visitors to the park choose which color hat they want, which informs their experience in the park of being a good guy or bad guy. This distinction of white hat or black hat has become a metaphor more broadly for good guy or bad guy. In the hacking community white hat hackers hack ethically in order to find security flaws and work with companies to improve their defenses, while black hats villainously hack to steal information.
Beyond just how they look, some westerns also had the heroes and villains move in certain directions during pivotal scenes. Because most people are right handed, heroes would walk from left to right across the screen with their gun hand visible to the viewer, keeping their intentions known at all times. Villains would approach from right to left, with their gun hand hidden from the viewer, as if hiding their intentions from the audience.
Outside the western
Our association of black hats and villains extends beyond tv & movies. A study of 25 seasons of NHL hockey found that players wearing black are penalized more frequently than players in lighter colors. Whether the players in black really are more villainous and commit more penalties or just that the referees are biased by black clothes and think the players to be more villainous and probably deserving of more penalty time, is unclear.
One notable exception with our connotations to the color black is of course is the Man In Black, Johnny Cash, who sang that he wore black as a visible symbol of his solidarity with the marginalized people who our society has ignored & abandoned.