The ocean is salty because water dissolves minerals from rocks and soil, then rivers and runoff carry those minerals into the sea. Over very long periods, salts build up in seawater.
Why the salt stays behind
When ocean water evaporates, the water vapor rises but most dissolved salts stay in the ocean. This is one reason evaporation is important in the water cycle.
Is all ocean water equally salty?
No. Salinity can vary by location. Areas with heavy evaporation may be saltier, while areas with large river input, melting ice, or heavy rain may be less salty.
The ocean's saltiness is a slow result of geology, weather, rivers, and evaporation working together.