No matter what color carpet you have, first try to blot up as much of the coffee as you can, then sponge the area with cool water and blot. Then, mix 1/4 teaspoon of liquid dish soap, one tablespoon of white vinegar, and one cup of warm water. Using a clean, white cloth, sponge the stain with the mixture, applying a little bit at a time and blotting frequently with a dry cloth until the stain disappears. Add one or two more drops of dish liquid to the vinegar/water mix, if needed. Sponge with cold water to rinse and blot dry.
Credit: https://www.goodhousekeeping.com/home/cleaning/a47654/how-to-clean-carpet/
