Swimming is not one of the powers used by Rayman in the original Rayman game. If he falls into any body of liquid in the Dream Forest, the Caves of Skops or Candy Château, he will instantly lose a life. It is clear that he hasn't learned the ability to swim at this point.
In Rayman 2 and Rayman Revolution
In Rayman 2, Rayman is now able to swim underwater, but for only a limited time. He needs air bubbles in order to stay underwater without dying. There are certain bodies of water that Rayman can't go in, if he does, he loses some health.
In Rayman 3
In Rayman 3, Rayman uses the power to swim mainly in the Land of the Livid Dead. In the fourth phase of the world, it is revealed that he can now swim more freely with his helicopter hair and without needing air bubbles to survive.
In the Nintendo DS version of Rayman Raving Rabbids, Rayman earns the power to swim halfway through the game. The swimming shares many similarities to the swimming from Rayman 2, although there is no time limit on how long Rayman can stay under water this time around.
In Rayman Origins and Rayman Legends
For a while in Rayman Origins, the heroes can swim but not underwater, until they enter Sea of Serendipity and save the nymph Annetta Fish. She grants them the power to dive in the sea, allowing the team to continue through the world. In Rayman Legends, this power is given to the players from the start.
When Annetta Fish is saved, she grants the players the power to dive.
The player can swim underwater after Annetta Fish gives the power.