Non-US citizens travelling through the US on the way to or from Mexico, or stopping over there, may need a US visa. If there’s even a possibility you might stop in the US, unless you are Canadian or from a country on the US visa waiver programme (this includes Britain, Ireland, Australia, New Zealand, Singapore, the Netherlands, Denmark, Sweden, Norway and Germany, but not South Africa), obtaining a visa in advance is a sensible precaution. Application will normally involve making an appointment for an interview at a US embassy or consulate, which should be arranged as far in advance as possible; visit the website of the US embassy in your country of residence for further details.
Citizens of countries on the visa waiver programme will need to have a machine-readable passport and to apply online for authorization to travel via the Electronic System for Travel Authorization at w cbp.gov/xp/cgov/travel/id_visa/esta (this does not apply to arriving in the US by land); also, if your passport was issued after October 26, 2006, it must have an integrated information chip (further details can be found online at w travel.state.gov/visa/temp/without/without_1990.html). On entry you will be given an I-94 or I-94W form. Be sure to return it when you leave the US: if it isn’t returned within the visa expiry time, computer records automatically log you as an illegal alien. If for any reason you do not manage to hand in your form when you leave the US, you can mail it (with a letter of explanation and evidence of your departure from the US) to: DHS-CBP SBU, 1084 South Laurel Road, London, KY 40744, USA.
Many US airports do not have transit lounges, so even if you are on a through flight you may have to go through US immigration and customs. This can easily take two hours, so bear the delay in mind if you have an onward flight to catch.