We establish a Grothendieck--Lefschetz theorem for smooth ample subvarieties of smooth projective varieties over an algebraically closed field of characteristic zero and, more generally, for smooth subvarieties whose complement has small cohomological dimension. A weaker statement is also proved in a more general context and in all characteristics. Several applications are included.