Preimage of a dense set under continuous onto function

I know preimage of a dense set under open map is dense. Is it true that preimage of a dense set under continuous onto function is dense?

Actually when I did the problem that continuous onto image of a dense set is dense. Suddenly I thought that question. Is that true? If so, then how to prove?

Not true. Consider the identity map $$id: \mathbb{R} \rightarrow \mathbb{R}$$ where the first $$\mathbb{R}$$ is endowed with the discrete topology and the second, the euclidean topology. This map is continuous and surjective.
$$\mathbb{Q}$$ is dense in $$\mathbb{R}$$ under the Euclidean topology. Its inverse image under $$id$$ is also $$\mathbb{Q}$$. But $$\mathbb{Q}$$ is not dense in $$\mathbb{R}$$ under the discrete topology.
EDIT: OP asked the following: If we allow both $$X$$ and $$Y$$ to be $$\mathbb{R}$$ with the usual Euclidean topology. Will the hypothesis be true? The answer is no.
Consider the function: $$f: \mathbb{R} \rightarrow \mathbb{R}_{\ge 0}$$ by setting $$f(x) =0$$ if $$x<0$$ and $$f(x)=0$$ if $$x\ge 0$$. This map is continuous and surjective. The set $$D=(0,\infty)$$ is dense in $$\mathbb{R}_{\ge 0}$$. But its preimage under $$f$$, which is still $$(0,\infty)$$, is not dense in $$\mathbb{R}$$! A huge reason is because the map $$f$$ is not open.
• is it true for real analysis i. e, if we take domain and codomain are $\mathbb{R}$ with usual topology then result is true? – Siraj Jun 12 at 15:41