# Finding a closed set inside an open one

Suppose I have a continous map $f : X \to Y$ between two topological spaces and I am given a neighborhood $O \subset Y$ of $f(x) \in Y$. Of course $U:= f^{-1}(O)$ is again an open set containing $x$. Now I would like to find a closed neighborhood $A \subset U$ of $x$. Is this possible for arbitrary spaces $X$ and $Y$ or do I need them to be Hausdorff, compact, ...?

-

$\newcommand{\cl}{\operatorname{cl}}$You want $X$ to be regular, meaning that whenever $x\in U\subseteq X$, and $U$ is open, there is an open $V$ such that $x\in V\subseteq\cl V\subseteq U$.
It isn’t enough to require that $X$ be Hausdorff, since there are Hausdorff spaces that are not regular. Let $X=Y$ be any such space, and let $f$ be the identity map. Then any $x\in X$ and $U\subseteq X$ witnessing the non-regularity of $X$ also witness the failure of $f$ to have the property that you want.
Added: Here’s an example of a Hausdorff space that’s not regular. Let $X=\Bbb R$, and let $\tau$ be the usual topology on $X$. Let $S=\{2^{-n}:n\in\Bbb N\}$, and let $$\mathscr{B}=\tau\cup\{U\setminus S:U\in\tau\}\;;$$ $\mathscr{B}$ is a base for a topology $\tau'$ on $X$. Clearly $\tau'\supseteq\tau$, and $\tau$ is Hausdorff, so $\tau'$ is Hausdorff. Let $U=\Bbb R\setminus S\in\tau'$. Then $0\in U$, but there is no $V\in\tau'$ such that $0\in V\subseteq\cl V\subseteq U$: if $0\in V\in\tau'$, there is an $m\in\Bbb N$ such that $2^{-n}\in\cl V$ for all $n\ge m$.