Some types of fish congregate at the water's surface in the tank to gain access to more oxygen, usually due to poor oxygenation of the tank's water. Other fish, such as bettas, breathe air from outside the tank, so they stay near the top.
Cloudy or silt-filled water might make it difficult for fish to breathe. They move to the top of the tank where they can obtain more oxygen. Changing the tank's water on a regular schedule and treating it with the appropriate nitrates can reduce this problem. Checking the oxygen levels in the tank's water helps fish owners maintain the proper balance so fish can breathe.