The Source of the Problem
Most of the time, gnats on houseplants are caused by fungus growing on the soil. Preventing this fungus is as easy as reaching for the watering can—reaching for it less, that is. Over-watering plants results in soil that stays damp, especially if the plants' foliage prevents light from hitting the surface of the soil. This creates an environment that is ideal for the growth of fungus.
Allowing the soil to dry out between waterings, at least on the surface, will prevent the environment that fungus needs in order to grow. By preventing the fungus, the food source for gnats is removed, and so are the gnats.
You can also prevent gnat infestations on your houseplants by following these tips: 1) Check for infestations before bringing new plants into the house. If you discover that you have bought a plant that has gnats or gnat larvae on the soil, repot the plant before bringing it into the house. 2) Add perlite, sand or gravel to the soil of your houseplants. Perlite, sand, and gravel all help soil to drain water more effectively, and therefore prevent the damp soil that fungus needs to grow. 3) Weather permitting, remove an infested plant outside as soon as gnats are spotted. Gnats have natural predators outdoors, which will decrease the number of gnats around your plant. Leave the plant a few days, repeat if possible, then bring the plant back inside when there are no more signs of an infestation.
Gnats Are Here: Now What?
If you already have gnats growing on your plants, then the first thing to do is to stop watering your plants. Allowing the top inch of soil to dry out will kill the fungus—and the larvae the gnats have left there—and eventually the gnats.
In the meantime, here are a few ways to get rid of the gnats you already have, including small vinegar flies that resemble gnats: 1) Trap flying gnats around houseplants by covering yellow paper or cardboard with petroleum jelly, which will create a sticky graveyard for gnats who are attracted. 2) Fill a jar with vinegar, cover it with a lid or piece of aluminum foil with holes punched in, and sit it near the plant(s). Gnats, who are attracted to the scent of vinegar, will fly into the jar, but will be unable to get out. 3) Remove the top inch of soil from your infested plants, and replace with sterilized potting soil. 4) Spray the plant with a ready-to-use Bt insecticide, covering the plant's foliage and the soil. Repeat the application every three to four days to keep the gnats under control.