Planets typically are considerably more metal-rich than even the most metal-rich stars, one indication that planet formation must differ greatly from star formation. There is general agreement that terrestrial planets form by the collisional accumulation of solids composed of heavy elements in the inner regions of protoplanetary disks. Two competing mechanisms exist for the formation of giant planets, core accretion and disk instability, though hybrid combinations are possible as well. In core accretion, a higher metallicity in the protoplanetary disk leads directly to larger core masses and hence to more gas giant planets. Given the strong correlation of gas giant planets detected by Doppler spectroscopy with stellar metallicity, this has often been taken as proof that core accretion is the mechanism that forms giant planets. Recent work, however, implies that the formation of gas giants by disk instability can be enhanced by higher metallicities, though not as dramatically as for core accretion. In both scenarios, the ongoing accretion of planetesimals by gas giant protoplanets leads to strong enrichments of heavy elements in their gaseous envelopes. Both scenarios also imply that gas giant planets should have significant solid cores, raising questions for gas giant interior models without cores. Exoplanets with large inferred core masses seem likely to have formed by core accretion, while gas giants at distances beyond 20 AU seem more likely to have formed by disk instability. Given the wide variety of exoplanets found to date, it appears that both mechanisms are needed to explain the formation of the known population of giant planets.