You may also be interested in Cookbook:Butter.
Margarine is a butter substitute, invented in France in the year 1869 by a French chemist Hippolyte Megè-Mouriès. This was done in response to a challenge proposed by Emperor Louis Napoleon III to produce a low cost butter alternative just to keep both the soldiers and French people nourished. Hippolyte Mege-Mouries accepted the challenge and created recipe for oleomargarine, which would later be renamed as margarine and would eventually evolve into the lovely spread that we enjoy today. According to the US FDA regulations it must consist of 80% fat. Normally in the US, this is various partially hydrogenated vegetable oils and emulsifiers accounting for the fat portion, while the remaining 20% consists of primarily water. To make it taste like butter, butter flavor (which is not generally vegan unless otherwise specified) is added to give it a more butter-like taste, and salt is also generally added, as butter flavor has very little taste without salt.
Margarine works quite well in baking, although the taste and texture can't quite match butter. It is sold in stick or tub form. Margarine in stick form is better for cooking, because it can be easily measured and has melting properties similar to butter. However, margarine in a tub (soft margarine) is easier to spread - but often functions slightly more like oil when you are baking, due to the softer texture.
It is important to note that a wide variety of products are considered margarine, while they are technically actually vegetable oil spreads and similar products with lower levels of oil. Even some stick products widely used and considered margarine are not technically margarine. As you reduce the fat content, it alters the properties, so use caution when baking with products that appear to be margarine but do not actually say that anywhere on the package. Soft spreads are particularly problematic, as some may have so little fat they are considered fat free.
Typical margarine has less saturated fat than butter but it has instead large amounts of potentially more harmful trans fat created during the hydrogenation process. It is important to note that while most margarine products available in the US today are produced using partially hydrogenated oils which contain trans-fats, margarine can be made using other vegetable oils that are not partially hydrogenated, resulting in a trans-fat free product. All margarine produced in Australia has been trans-fat free since 1996. Fully hydrogenated oils may also be used - when an oil is fully hydrogenated, no trans-fats remain.
Some margarines purport to be "trans-fat free" but still contain partially hydrogenated oils - this is often puzzling to people who know that partially hydrogenated oils always means the product contains trans-fat. In most jurisdictions, a certain level of transfats is allowed while calling the product "trans-fat free" - in the U.S. anything under 0.5 g is allowable while being reported as 0 g. This is quite disturbing, because while the FDA and USDA do not specify a maximum intake, the suggest intake at the press conference unveiling the new food pyramid was no more than 2 g per day. That means four servings of "trans-fat free" food could put you at your maximum intake of trans-fat for the day. This is particularly problematic in margarine where the serving size can be easily manipulated to obtain a value of less than 0.5 grams per serving.