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.

A subset $A$ of a topolgical set $X$ which is open and closed is a union of connected components. To see this, consider $x\in A$ and $C$ is connected component, $C\cap A$ is closed and $C\cap (X-A)$ is also closed, you deduce that $C\cap (X-A)$ is empty since $C$ is connected, henceforth $C\subset A$.
