Seeing tiny white worms swimming in an aquarium can be jarring, but these worms are actually quite common. They are called planaria, and are tiny flatworms that frequently grow as a result of uneaten food in the aquarium. Though the worms aren't directly harmful to the fish, they are symptoms of an aquarium cleanliness problem.
Clean your tank.
Completely drain the tank and replace with clean water. Remove the aquarium gravel and rinse it well. Check your filters and replace or clean if they are dirty.
Feed your fish only what they can eat in 15 minutes.
Flatworms are most often caused by excess food that has built up in the tank's gravel, so it's vital to deprive them of their food source in order to prevent them from returning.
Treat your aquarium with aquarium salt.
Most pet stores sell this treatment, which can get rid of worms and correct hygiene and pH problems. Use 1 tbsp for every five gallons of aquarium water.
Remove the gravel.
If you're still having trouble with worms after cleaning the tank and treating with salt, temporarily removing the gravel can completely eliminate the worms. After the worms are gone for a week or more, you can put the gravel back in the aquarium.
Don't try to kill the worms with poison or other treatments. Doing so may kill your fish.