Chromium is primarily responsible for stainless steel's corrosion resistance.
Stainless steel contains at least about 10.5 percent chromium by mass under the widely used definition. When exposed to oxygen, chromium forms a thin, adherent layer of chromium(III) oxide on the surface. This passive layer greatly slows further corrosion and can reform if the surface is lightly damaged.
Stainless steels are iron-based alloys, so they are not completely immune to corrosion. Chlorides, acids, high temperatures, poor maintenance, and crevices can still cause pitting or other forms of attack. The exact performance depends on the grade and environment.
Nickel is important in many stainless steels because it stabilizes certain crystal structures and improves toughness and corrosion performance. Molybdenum can improve resistance to chloride pitting. However, chromium is the key element that gives stainless steel its defining passive protective film.