So your recipe calls for "an onion."
That's not very specific, and you may find yourself at the grocery store staring at mountains of varieties. Dinner isn't going to be ruined if you use a red onion where you should use a yellow onion. That said, there are some onion best practices, and here they are.
MOST COMMONLY USED:
Best for almost everything major: roasted meat dishes (pot roast, rack of lamb, roast chicken, etc.)...
...or as a flavor base for sauces, soups, and stews.
Yellow onions are the most common variety you should cook with. They have thin layers of white flesh and a tough, brownish-yellow skin. They're very astringent — astringency is that sharp, almost spicy flavor that onions are known for — but also have a lot of sugar. When cooked, this onion loses its astringency, gets super sweet, and turns a light brown color.
Best for frying, for making rings, for French onion soup...
...or for baked gratins and roast veggie dishes.
Sweet onions are similar to yellow ones, but their distinct flavor is better for certain things. A sweet onion has thick layers, which makes it great for slicing into rings. Because of its high sugar content and a low sulphur content, it is very sweet without being as pungent or spicy as other types of onion. They are great for frying — think battered things, like onion rings or the infamous bloomin' onion — and are also perfect for French onion soup, since they add so much sweetness. They're also perfect for roasted vegetables (while yellow onions are good for meat roasts, which have a more savory flavor), and in baked gratins. ALSO KNOWN AS: Vidalia onions, Walla Walla onions
CRUNCHIEST AND SHARPEST:
Best for salsa or vegetable chutney, or in sautéed or stir-fried vegetables for extra crunch.
White onions are less common, and are used mostly in Mexican cooking. They're larger than other varieties, with thin, papery skin. They are sharp, astringent, and not very sweet, and they're super crispy because of their high water content.
EASIEST TO EAT RAW:
Best for guacamole, pickling, slicing thin for salads...
...or grilled, on burgers, and on sandwiches.
Red onions are milder, and add a little bit of color. A red onion is crisp and a little bit sweet, with a slightly bitter aftertaste. It isn't as pungent as a yellow onion (read: less "onion breath" and fewer tears while slicing), but still has a pretty strong flavor.
Best for salad dressings, mignonettes, and cooked vinegary glazes...
...or in egg casseroles or as garnishes.
Though a shallot is not technically an onion, it has a similar flavor and is less overpowering. Shallots grow in clusters with multiple cloves, like garlic, but their flavor is really similar to that of a mild red onion. It's sweet with a little bit of spiciness. Shallots are the best choice for vinaigrette and mignonette (a super chunky vinaigrette that's eaten with oysters or other shellfish), or in cooked vinegar sauces (like balsamic glaze or gastrique). Shallots are also great in quiche or other egg dishes, since they're smaller than onions and aren't as chunky. Also, thinly sliced shallots are a great, simple garnish for vegetable dishes, either raw or fried.