Notation for a constant vs a variable?

I have a straight line $y=f(x)$, i.e. $$y=kx+m$$ $k, m$ are constants. $x$ is a variable. But is it correct to write $$k,m\in\mathbb R$$ and $$x\in \mathbb R \qquad?$$

Is this notation correct for both constants and variables? Or does the notation differ between constants and variables?

You need to indicate which are fixed and which are not. So, it is correct to write $k,m,x\in\mathbb{R}$, but $k$ and $m$ are fixed while $x$ is not.
Alternatively (and more commonly), you would write $f:\mathbb{R}\rightarrow\mathbb{R}$ and $f(x)=kx+m$. Here, you are indicating that $x$ is the variable because of the $x$ appearing in $f(x)$ and you are indicating that $x$ is coming from $\mathbb{R}$ by $f:\mathbb{R}$.
In this second way, you are making a distinction between the function $f$ and the formula for $f(x)$. $f$ is a function whose input is in $\mathbb{R}$ and whose output is also in $\mathbb{R}$. Whereas $f(x)=kx+m$ gives the formula for calculating the values of $f$.
Your notation says true things, but maybe what you want is to emphasize that the $x$ can vary, like in the notation \begin{align*} f:\mathbb R&\to\mathbb R\\ x&\mapsto f(x)=xk+m,& k,m\in\mathbb R. \end{align*}