If $X$ is a CW complex, then the path components of $X$ are the components of $X$. I'm self-learning Algebraic Topology from Rotman's Introduction to Algebraic Topology and I've come across this problem:

If $X$ is a CW complex, then the path components of $X$ are the components of $X$.

The proof states:  If $A$ is a path component of $X$ and $Y$ is a component of $X$ containing $A$ and since $A$ is both open and closed, then it follows that $A=Y$.
How does it follows here?  I don't see the connection.

You can also just prove this directly from the definition of a CW-complex.  By "cell" I will always mean "closed cell", i.e. the image of the characteristic map of a cell.  Note that each cell is path-connected, being the continuous image of $\Delta^n$ for some $n$.  Now define an equivalence relation $\sim$ on cells by saying $a\sim b$ iff there exist cells $e_0,e_1,\dots,e_n$ with $e_0=a$, $e_n=b$, and $e_i\cap e_{i+1}\neq \emptyset$ for $i=0,\dots,n$.  Note that in that case, the union $\bigcup e_i$ is path-connected, so $a$ and $b$ are in the same path component of $X$.
Now for each equivalence class $S$ of cells under $\sim$, consider the set $C_S\subseteq X$ which is the union of all the elements of $S$.  By the observation above, $C_S$ is path-connected.  On the other hand, I claim each $C_S$ is open.  Indeed, any cell which intersects $C_S$ is an element of $S$ and therefore is entirely contained in $C_S$, so the inverse image of $C_S$ under the characteristic map of any cell is either empty or the entire space, and in particular is open.  So the sets $C_S$ form a partition of $X$ by open sets.  Thus any connected component of $X$ is contained in some $C_S$.  But since each $C_S$ is path-connected, this means the sets $C_S$ themselves are the connected components of $X$, and also the path-components of $X$.
