Fish have evolved bright colors for several reasons:
Camouflage: Some use bright colors to blend with surroundings or disrupt their body outline.
Attracting mates: Bright colors can signal health and fitness, and help fish recognize their own species.
Communication: Bright colors can warn predators of toxicity (aposematic coloration) or establish territories.
Other reasons: Thermoregulation and protection from UV radiation.
Examples include clownfish (warning colors), mandarin fish (mate attraction), and peacock mantis shrimp (signals to rivals and mates). The reason is usually a combination of factors depending on the species and environment.