Welcome new contributor. This follows by combining several results from Hartshorne's *Algebraic geometry*. Let $k$ be a field.

**Definition.** A closed subset $Z$ of a locally Noetherian scheme $X$ has **pure codimension** $\geq c$ **locally everywhere** if $\text{dim}_p(X) \geq c + \text{dim}_p(Z)$ for every point $p$ of $Z$.

**Proposition.** Every normal, finite type, separated $k$-scheme contains a quasi-projective open subscheme whose closed complement has codimension $\geq 2$ locally everywhere.

**Proof.** Every normal scheme is a disjoint union of its irreducible components. Hence it suffices to prove this for an *irreducible* scheme. Let $X$ be such a scheme. Denote the dimension by $d$.

Let $I$ be the set of ordered pairs $(U,U^o)$ of a nonempty open subscheme $U$ of $X$ and a quasi-projective open subscheme $U^o$ of $U$ whose complement has dimension $\leq d-2.$ This has a lexicographic partial order by set inclusion. Every open affine subscheme of $X$ gives an element of $I$, so $I$ is not empty. By the Noetherian hypothesis, there exists a maximal element of $I$, say $(U,U^o).$

By definition, there exists a locally closed immersion of $k$-schemes, $$i:U^o \hookrightarrow \mathbb{P}^n_k.$$ By Zariski's Main Theorem, the maximal domain of definition of the rational transformation $i$ on $X$ is an open subscheme whose closed complement has dimension $\leq d-2$. Thus, there exists a closed subset $Z$ of $X$ containing $U\setminus U^o$, having dimension $\leq d-2$, and such that $i$ is a regular morphism on $X\setminus Z$.

By way of contradiction, assume that the complement of $U$ is nonempty. For any open affine $V$ of $X$ that intersects the complement, there exists a locally closed immersion of $k$-schemes, $$j:V\hookrightarrow \mathbb{P}^m_k.$$ The maximal domain of definition of $j$ on $X$ is the open complement of a closed subset, say $Y$. By Zariski's Main Theorem, $Y$ has dimension $\leq d-2$.

On the open complement $W$ of $Z\cup Y$, consider the product $k$-morphism, $$(i,j):W \to \mathbb{P}^n_k \times_{\text{Spec}\ k} \mathbb{P}^m_k.$$ Since the restriction of $i$ to $U^o\cap W$ is a locally closed immersion, also the restriction of $(i,j)$ to $U^o\cap W$ is a locally closed immersion. Similarly, the restriction to $V\cap W$ is a locally closed immersion. Thus, the restriction to $(U^o\cup V)\cap W$ is a locally closed immersion. Since the Segre map is a closed immersion, it follows that $(U^o\cup V)\cap W$ is a quasi-projective $k$-scheme.

Thus, $(U\cup V,U^\cup V)$ is an element in $I$ that is strictly larger than $(U,U^o).$ This is a contradiction of maximality. Therefore, by contradiction, $U$ equals $X$. **QED**

**Corollary.** Every reduced, finite type, separated $k$-scheme contains a quasi-projective open subscheme whose closed complement has codimension $\geq 2$ locally everywhere.

**Proof.** Let $X$ be a reduced, finite type, separated $k$-scheme. Denote by $X_n$ the maximal open subscheme of $X$ that is normal. Since $X$ is reduced, this is a dense open subscheme.

By the Noether Normalization Theorem, the normalization of $X$ is a finite morphism. Denote this finite morphism by $$\nu:\widetilde{X}\to X.$$ By the proposition, there exists a quasi-projective open subscheme $\widetilde{X}^o$ of $\widetilde{X}$ whose complement has codimension $\geq 2$ locally everywhere. Let $\widetilde{L}$ denote an ample invertible sheaf on $\widetilde{X}^o$.

Let $J$ denote the set of triples $(U,U^o,L_U,\phi)$ of an open subscheme $U$ of $X$ containing $X_n$, an open subscheme $U^o$ of $U$ contained in $\nu(\widetilde{X}^o)$ and whose complement $U\setminus U^o$ has codimension $\geq 2$ everywhere, an invertible sheaf $L_U$ on $U^o$, and an isomorphism $\phi$ from $\nu^*L_U$ to the restriction of $\widetilde{L}$ to $\nu^{-1}(U^o)$. Since $\widetilde{L}$ is ample, also $\widetilde{L}^o$ is ample, cf. Exercise III.5.7(d) of Hartshorne's *Algebraic geometry*. The set $J$ is partially ordered by lexicographic set inclusion followed by extension of invertible sheaves and isomorphisms. Since $(X_n,X_n\cap \nu(\widetilde{X}^o),\nu_*\widetilde{L}|,\text{Id})$ is one element of $J$, the set $J$ is not empty. By the Noetherian hypothesis, there exists a maximal triple $(U, U^o,L_U,\phi)$.

By way of contradiction, assume that $U$ does not equal $X$. By maximality, the closed complement of $U$ has pure codimension $1$. Thus, the closed image $\nu(\widetilde{X}\setminus \widetilde{X}^o)$ contains no irreducible component of the complement of $U$. Let $p$ be a generic point of the complement of $U$. Thus, $p$ is not contained in $\nu(\widetilde{X}\setminus \widetilde{X}^o)$.

Since every invertible sheaf on Spec of a semilocal Noetherian ring is free, there exists an open neighborhood $V$ of $p$ contained in $\nu(\widetilde{X}^o)$ such that the restriction of $\widetilde{L}^o$ to $\nu^{-1}(V)$ is free. Up to shrinking $V$, we may assume that $U^o\cap V$ is contained in the normal locus $X_n$.

Define $L_V$ to be the structure sheaf on $V$. Define $\psi$ to be an isomorphism of the pullback of $L_V$ and the restriction of $\widetilde{L}$ to $\nu^{-1}(V)$. Since $U\cap V$ is contained in the normal locus of $X$, there is a unique isomorphism of the restrictions of $L_V$ and $L_U$ to $U\cap V$ compatible with $\phi$ and $\psi$. Thus, by glueing, there is a triple of $J$ whose open subsets are $(U\cup V, U^o\cup V)$. This contradicts maximality of $(U,U^o,L_U,\phi)$. Therefore, by contradiction, $U$ equals $X$. Finally, by Theorem II.7.6 of Hartshorne's *Algebraic geometry*, the open subscheme $U^o$ is quasi-projective. **QED**

**Theorem.** Every finite type, separated $k$-scheme contains a quasi-projective open subscheme whose closed complement has codimension $\geq 2$ locally everywhere.

**Proof.** For any two irreducible components of unequal dimension, say $d<e$, every irreducible component of the intersection is a proper subvariety of each irreducible component. Thus, the dimension of the intersection is $\leq d-1$. Since the dimension of the whole scheme is $\geq e$ at each point of the intersection, the intersection has codimension $\geq 2$ locally everywhere. Thus, without loss of generality, remove the intersection of any two irreducible components of unequal dimension so that every connected component of the scheme has pure dimension. Since the scheme is the disjoint union of its connected components, it suffices to prove the result for a connected scheme of pure dimension $d$.

By the previous corollary, the reduced locus contains an open subscheme whose closed complement has codimension $\geq 2$ locally everywhere and that supports an ample invertible sheaf. This quasi-projective open contains a quasi-projective open as above that is a union of two open affine subschemes. The intersection of these open affine subschemes is also affine, since the scheme is separated.

By Exercise III.4.2 of Hartshorne's *Algebraic geometry*, each of these open affines in the reduced scheme is the intersection of the reduced scheme with an open affine of the original scheme. By Exercise III.4.6 of Hartshorne's *Algebraic geometry*, the ample invertible sheaf extends to each of these open affines in the original scheme. Also, the glueing isomorphism of these invertible sheaves on the intersection open affine of the reduced scheme extends to a morphism of coherent sheaves on the intersection open affine of the original scheme. By Nakayama's Lemma, since this morphism restricts to an isomorphism on the reduced scheme, this morphism is an isomorphism. Thus, by glueing, there is an invertible sheaf on the union of these two open affines whose restriction to the reduced scheme is the original ample invertible sheaf.

Applying Exercise III.5.7(d) once more, this invertible sheaf on the union of the two open affines is an ample invertible sheaf. Thus, the union of the two open affines in the original scheme is quasi-projective by Theorem II.7.6 of Hartshorne's *Algebraic geometry*. **QED**

Finally, let $X$ be an integral, finite type, separated $k$-scheme of dimension $d$. As in the corollary, let $X^o$ be an open subscheme of $X$ that is quasi-projective and whose closed complement has dimension $\leq d-2$. By Bertini's Theorem, for a sufficiently ample Veronese re-embedding of $X^o$, there exists an irreducible hyperplane section of $X^o$ whose complement is an affine open $U$ of $X^o$. The complement of $X^o$ in $X$ has dimension $\leq d-2$ , yet every irreducible component of $X\setminus U$ has dimension $d-1$ (**ed.** this holds by Corollaire 21.12.7 of EGA IV, as noted by @kartop_man below). Thus, the open subset $X^o\setminus U$ of $X\setminus U$ is a dense open subset. Therefore, also $X\setminus U$ is irreducible.

3more comments