Fungus gnats are about 1/8 inch long and are a shade of gray or black. The larvae are nesting in the soil, feeding on the organic matter. They can be harmful to the roots and crowns of the plants, but the adult fungus gnats that you see flying around are harmless, except for the fact that they lay the eggs which turn into the larvae.
One of the simplest ways to get rid of fungus gnats in potted plants is to replant in new potting soil. Do this outdoors and away from your home. Also, stop watering your plants and let the soil dry out completely. This will kill the larvae. If you can't do this or your plants are outdoors where rainfall is likely, you can apply a pesticide labeled to kill fungus gnats. Always use pesticides according to manufacturer directions.
Soapy water is often used to kill sap eating insects, such as spider mites, aphids, mealy bugs and scale. Fungus gnats do not stand on the leaves like these bugs do and are therefore not as easy to kill in this manner. However, if the fungus gnats are infesting container plants and you are changing the soil, use hot soapy water to thoroughly clean out the pots before you use it with fresh new soil. This will help kill any eggs you may not see.
The best way to prevent fungus gnats is to allow the soil to dry out to a depth of 2 inches before watering it again. Soil that is consistently wet is the perfect breeding ground for fungus gnats. In addition, clean up the plant debris as it falls and cut off browning or decaying foliage, especially near the bottom of the plant. If you take your potted plants outdoors for the summer, carefully inspect them for any insects before bringing them back indoors.