Hydrocarbons are the class of organic chemical compounds composed only of carbon and hydrogen. The carbon atoms join together to form the framework of the compound, and the hydrogen atoms attach to them in many different configurations. Hydrocarbons are the principal constituents of petroleum and natural gas.