TITLE: How to prove the continuity of the metric function?
QUESTION [29 upvotes]: Given a metric space $(X,d)$, how to prove that the function $d \colon X \times X \to \mathbf{R}$ is continuous? 
If we take any two arbitrary real numbers $a$ and $b$ such that $a < b$, then we need to show that the set $d^{-1} (a,b)$ given by 
$$ d^{-1} (a,b) :=  \{ (x, y) \in X \times X | a < d(x,y) < b \} $$
is open in the product topology on $X \times X$. 
A basis for this product topology is the collection of all cartesian products of open balls in $(X,d)$.

REPLY [2 votes]: Let $(x,y)\in d^{-1}(a,b)$. Define $\epsilon=\frac{1}{100}\min(d(x,y)-a,b-d(x,y))$.
Then for any point $(\xi,\gamma)\in B(x,\epsilon)\times B(y,\epsilon)$, we have
$${\color{blue} d(\xi,\gamma) }\leq d(\xi,x)+d(x,y)+d(y,\gamma)<2\epsilon+d(x,y)<{\color{blue}b}$$
and
$${\color{blue} a}<d(x,y)-2\epsilon <d(\xi,\gamma)+\underbrace{ d(x,\xi)-\epsilon}_{<0}  +\underbrace{d(y,\gamma)-\epsilon}_{<0}<{\color{blue} d(\xi,\gamma)}.$$
That is to say
$$(x,y)\in B(x,\epsilon)\times B(y,\epsilon)\subseteq d^{-1}(a,b).$$
Hence any point $(x,y)\in d^{-1}(a,b)\subseteq X\times X$ is surrounded by some open set contained in $d^{-1}(a,b)$.
(After typing this answer, I realized this is EXACTLY the same as the answer by @k.stm; so thanks also to his contribution. I guess it will be hard to write a different one.)