When considering why the ocean is salty, the most basic explanation centers on the water cycle, the method by which water is continuously distributed around the Earth.
The water cycle is a never-ending process. Since we have to start somewhere, and any cycle, like a wheel really has no beginning or end, let's start at the oceans.
In the ocean water is continuously evaporating from the surface. This happens everywhere there is water, just like a puddle in the street in front of your house will evaporate over time leaving the street dry, eventually. This water vapor enters the atmosphere; everywhere in our atmosphere there is some water vapor that has come from evaporation. In some places there is a lot of water vapor, and people talk about how humid it is. Other places have little water vapor, and you hear comments about "but it's a dry heat". But, even in the driest deserts there is still some water vapor in the air.
But, water vapor doesn't stay in the air forever, eventually, it comes down.
Given the right conditions of water vapor density, temperature and airflows, and many other components, water vapor condenses into small droplets and forms clouds. If the droplets get large enough they fall as rain or snow. While rain and snow will contain some dissolved solids from the atmosphere (particles of dust are actually needed for the water vapor to condense) the concentrations of those dissolved solids are very low.
After the rain and snow falls to the ground it begins an inexorable flow downhill. Unless something temporarily stops this flow, forming a pond or a lake, the water will flow until it reaches the lowest point it can, for most of the world this is the sea. As this water flows more and more materials are dissolved or picked up in suspension. High mountain streams are usually quite clear and clean while the big, sluggish rivers at lower elevations are usually muddy and dirty. This is because as the water flows it stirs up soil and picks up what it can dissolve and carries these materials with it to the sea. The further the water has gone the more materials are carried with it. Big rivers like the Mississippi get nicknames like "Big Muddy" because of all of the sediment load carried by the river.
Even when a river enters the sea, however, most of these rivers are still relatively "fresh", or have relatively low concentrations of dissolved salts. Since water is a powerful solvent, it will dissolve almost anything to one degree or another, all water has some dissolved materials, but, until those salts are concentrated in the ocean, most rivers and lakes are considered to be fresh. On the other hand there are "salt rivers". Some rivers flow over soil that has a lot of salt in it and the rivers will dissolve this salt and carry it with them in their flow to the sea.
Once the water in a river reaches the sea the cycle starts all over with the water being evaporated into the atmosphere, falling as rain or snow and flowing, once again, to the sea.
However, most of the stuff that the river picks up over the land doesn't evaporate with the water, and stays in the oceans. (There are other mechanisms, actually other cycles, that serve to keep the levels of salt in the oceans fairly constant but those are beyond the scope of this article.)
One thing this tells us, that we should never forget, all water eventually flows to the sea. And, everything we put into water is concentrated in the oceans. We should take care with how we handle the water we use.
But, why salt? There are lots of other things that dissolve in water so why do we not have "sweet" oceans, from all of the dissolved sugar?
That comes down to a lot of basic chemistry, physics and biology.
Certainly organic chemicals, like sugar, dissolve in water. However, these complex chemicals will be consumed by organisms in the ocean and converted to more basic chemicals so they really won't stay in the oceans in the form we're used to. Zooplankton will consume dissolved organic chemicals and use those chemicals for growth and for energy. If a molecule of sugar were to reach the ocean, microscopic organisms would consume that, convert some of it to carbon dioxide and water, and use some of it as mass for growth. Larger and larger organisms then feed upon these microscopic organisms in another cycle called the carbon cycle. Organic chemicals in the ocean are tied up in the form of life.
This leaves inorganic, or non-carbon chemicals, in the sea. But, this still doesn't explain why the salt in the oceans is mostly sodium chloride (NaCl), or what we commonly know as table salt.
In actuality, there are lots and lots of chemicals dissolved in sea water. In fact, to some degree virtually every element known to man is dissolved in the oceans. Most of those elements are dissolved in the form scientists call salts. To understand that we need to understand what a salt is.
A salt is a neutral (not acidic or basic) chemical compound made up of two or more elements that, when dissolved dissociate into positive and negative ions. Salts can be organic, or inorganic, however as said before, organic compounds are usually broken down through biological processes and don't stay in solution in the oceans.
There are also elements that don't form salts, in other words, they don't dissolve as separate ions but only as complete chemical compounds. One example is silicon dioxide, which makes up quartz or sand. Most of these inorganic compounds do not dissolve easily in water. If sand dissolved easily in water we wouldn't have any beaches. Any of these chemicals that are carried to the ocean generally do so as suspensions, not solutions. These suspensions settle to the bottoms of the oceans because they're not dissolved.
This means that the vast majority of the compounds in the oceans will be inorganic salts. And, the quantities of any of these salts will depend on several factors.
One major factor is the prevalence of the chemical on the Earth. The 10 most common chemicals on the Earth's surface, and in the oceans, are;
Of these elements, hydrogen and oxygen being the most common in seawater is obvious, hydrogen and oxygen are what water is made of. As to the chemicals in the crust of the Earth that don't show up as much in seawater; silicon, aluminum and iron, these are the elements that don't form soluble salts. These are the elements that are carried in suspension, not in solution, and fall to the bottom of the sea, as in the example above.
So, calcium, sodium, magnesium and potassium, are the common elements in the Earth's crust that readily form soluble salts.
But, something interesting shows up in comparison of the relative amounts. First, chlorine is the fourth most common element in seawater, but it turns out to be 19th most common in the Earth's crust. And sulfur is the sixth most common element in seawater but is the 16th most common in the crust.
Why are these elements so common in seawater?
It turns out that these are the most common elements that can form salts with calcium, sodium, magnesium and potassium. And, while sulfur is more common than chlorine in the Earth's crust, due to the chemical properties of these elements, chlorine forms a more soluble salt while sulfur is often in the crust in chemical compounds that are less soluble.
Second interesting thing about the relative amounts of these chemicals is that calcium is more common in the Earth's crust than sodium, but sodium is far more common in seawater. This difference is due to one cause, the same one that reduces the amounts of organic chemicals in the oceans. That cause is life.
Shellfish in the oceans remove calcium to create their shells. These shellfish, when they die, either stay on the bottom (if that's where they lived) or sink to the bottom. The calcium that arrives in the oceans dissolved in the water is, through this mechanism, taken out of the oceans. Later changes can bring the calcium to the land in the form of limestone, which is then dissolved by water and returned to the oceans, in yet another cycle.
This leaves what we commonly know as salt, dissolved sodium and chlorine ions, to be the most common substance in the oceans, other than water, of course.