Because closet doors are normally closed, hiding away whatever is inside, sometimes closets can develop strange or musty odors. Cleaning and airing out your clothes is a good way to combat these smells, but you may be looking for something that you can also leave in the closet which will draw out bad odors. You have a number of options, and you can use more than one at once.
Baking soda is known for keeping bad smells out of a refrigerator, but it can work in a closet, too. Baking soda needs good air circulation to work well, so put it on a shelf or someplace where air will reach it. Ensure to put it in a place where you won't knock it over accidentally. You'll need to change the baking soda regularly, and baking soda is only helpful for certain kinds of smells. You can also sprinkle baking soda on the carpet or anything particularly smelly, such as shoes, then vacuum it later.
Activated charcoal is a substance often created from regular charcoal. It's highly porous and is good at absorbing contaminants. It's typically used in filters -- such as water filters or air masks -- but its absorbing abilities make it useful for drawing out bad smells. Put activated charcoal into a pouch that air can flow through or use a sock. Activated charcoal can absorb more kinds of smells than baking soda and can even absorb smells that you might find pleasant, such as floral scents. However, it can begin to release the smells if it becomes too saturated, so change it regularly. It's also rather expensive in comparison to your other options.
Fill a bowl with white or apple cider vinegar, then put it on the floor of your closet. Close the door and leave it overnight. You can do the same thing with bleach. Bleach is more powerful; however, the smell is worse than vinegar and bleach is more dangerous. For additional smell removal, add 1/2 cup of vinegar to a bucket of warm water, then scrub the walls of the closet with the mixture.
Coffee grounds can also eliminate bad odors. Fresh, unbrewed grounds are best, but you also can use the grounds that remain after you've made a cup of coffee. Put the grounds into a bowl, then leave it on the floor of your closet. Close the door and leave it overnight. To add a pleasant scent to the grounds, sprinkle on some vanilla extract. This is a particularly effective method of combating a smoky smell from cigarettes or cigars.
There are a number of items that you can safely leave inside of your closet to make it smell nice, although this is masking the problem rather than drawing out a smell. Soak a cotton ball in something that smells pleasant such as vanilla extract or lemon juice, then leave it someplace inside the closet. Cleaning the inside with warm water that has a little lemon juice added also leaves a pleasant scent. You can also leave little sachets inside the closet that are filled with potpourri containing cinnamon, dried oregano or lemon peel. Putting dryer sheets in the closet can also improve the smell.