[proofplan]
We prove both directions directly from the definition of connectedness. If a nontrivial clopen set exists, then it and its complement form a separation of $X$, so $X$ is disconnected. Conversely, if $X$ is disconnected, a separation of $X$ produces a nonempty proper subset that is simultaneously open and closed.
[/proofplan]
[step:Show that a nontrivial clopen subset disconnects the space]
Assume $(X,\tau)$ is connected. Let $A \subset X$ be both open and closed in $(X,\tau)$. We prove that $A=\varnothing$ or $A=X$.
Suppose, for contradiction, that $A \neq \varnothing$ and $A \neq X$. Define $B := X \setminus A$. Since $A$ is closed, $B$ is open. Since $A$ is open, both $A$ and $B$ are open subsets of $X$. Also $A \cap B = \varnothing$ by definition of complement, and $A \cup B = X$. Because $A \neq X$, the complement $B$ is nonempty. Thus $X$ is the union of two disjoint nonempty open subsets $A$ and $B$, which is a separation of $X$. This contradicts connectedness. Therefore every clopen subset of $X$ is either $\varnothing$ or $X$.
[guided]
Assume $(X,\tau)$ is connected, and let $A \subset X$ be both open and closed in $(X,\tau)$. We want to prove that no intermediate possibility can occur: $A$ must be empty or all of $X$.
Suppose instead that $A$ is neither empty nor all of $X$. Define the complement subset $B := X \setminus A$. Because $A$ is closed, its complement $B$ is open. Because $A$ is open by hypothesis, both $A$ and $B$ are open subsets of $X$.
Now we check the separation conditions one by one. By definition of complement,
\begin{align*}
A \cap B = A \cap (X \setminus A) = \varnothing.
\end{align*}
Also,
\begin{align*}
A \cup B = A \cup (X \setminus A) = X.
\end{align*}
The set $A$ is nonempty by assumption, and $B$ is nonempty because $A \neq X$. Hence $A$ and $B$ are two disjoint nonempty open subsets whose union is $X$.
This is exactly a separation of $X$. Therefore $X$ would be disconnected, contradicting the assumption that $(X,\tau)$ is connected. The contradiction shows that no nonempty proper clopen subset $A$ can exist. Hence every clopen subset of $X$ is either $\varnothing$ or $X$.
[/guided]
[/step]
[step:Show that a separation produces a nontrivial clopen subset]
Assume every clopen subset of $X$ is either $\varnothing$ or $X$. We prove that $(X,\tau)$ is connected.
Suppose, for contradiction, that $(X,\tau)$ is disconnected. Then there exist subsets $U,V \subset X$ such that $U$ and $V$ are open in $(X,\tau)$, $U \neq \varnothing$, $V \neq \varnothing$, $U \cap V = \varnothing$, and $U \cup V = X$. Since $V = X \setminus U$, the set $U$ has open complement, so $U$ is closed. Thus $U$ is both open and closed. Since $U \neq \varnothing$ and $V \neq \varnothing$, we also have $U \neq X$. Therefore $U$ is a clopen subset of $X$ different from both $\varnothing$ and $X$, contradicting the hypothesis. Hence $(X,\tau)$ is connected.
[/step]
[step:Conclude the equivalence]
The first step proves that connectedness implies the only clopen subsets are $\varnothing$ and $X$. The second step proves the converse implication. Therefore $(X,\tau)$ is connected if and only if every clopen subset of $X$ is either $\varnothing$ or $X$.
[/step]