Spherical unit vectors are three mutually perpendicular vectors \((\hat{r},\hat{\theta},\hat{\phi})\) that point in the directions of increasing radial distance, polar angle, and azimuthal angle, respectively.

To derive these vectors, we begin with the relationship between Cartesian and spherical coordinates (see diagram above):
$$x=rsin\theta cos\phi\; \; \; \; y=rsin\theta sin\phi\; \; \; \; z=rcos\theta\; \; \; \; r=\sqrt{x^{2}+y^{2}+z^{2}}$$
The position vector in Cartesian coordinates is \(\boldsymbol{r}=x\hat{i}+y\hat{j}+z\hat{k}\), or equivalently,
$$\boldsymbol{r}=rsin\theta cos\phi\hat{i}+rsin\theta sin\phi\hat{j}+rcos\theta\hat{k}$$
When \(r=1\), the position vector becomes the radial unit vector:
$$\hat{r}=sin\theta cos\phi\hat{i}+sin\theta sin\phi\hat{j}+cos\theta\hat{k}\;\;\;\;\;\;\;\;76a$$
The azimuthal unit vector \(\hat{\phi}\) lies in the \(xy\)-plane, which is spanned by the unit vectors \(sin\frac{\pi}{2}cos\phi\hat{i}=cos\phi\hat{i}\) and \(sin\frac{\pi}{2}sin\phi\hat{j}=sin\phi\hat{j}\). Since it is also perpendicular to the projection of \(\boldsymbol{r}\) onto that plane, it makes an azimuthal angle of \(\phi+\frac{\pi}{2}\) with the positive \(x\)-axis. Therefore,
$$\hat{\phi}=cos\left(\phi+\frac{\pi}{2}\right)\hat{i}+sin\left(\phi+\frac{\pi}{2}\right)\hat{j}=-sin\phi\hat{i}+cos\phi\hat{j}\;\;\;\;\;\;\;\;76b$$
The polar unit vector can then be determined using the cross product \(\hat{\theta}=\hat{\phi}\times\hat{r}\):
$$\hat{\theta}=\begin{vmatrix}\hat{i}&\hat{j}&\hat{k}\\-sin\phi&cos\phi&0\\sin\theta cos\phi&sin\theta sin\phi&cos\theta\end{vmatrix}$$
Expanding the determinant yields
$$\hat{\theta}=cos\theta cos\phi\hat{i}+cos\theta sin\phi\hat{j}-sin\theta \hat{k}\;\;\;\;\;\;\;\;76c$$
Eq76a, eq76b and eq76c give the three spherical unit vectors. To express the Cartesian unit vectors \(\hat{i},\hat{j},\hat{k}\) in terms of the spherical unit vectors, we perform a change of basis. Let the forward transformation be \(S=MC\), where
$$\begin{pmatrix}\hat{r}\\\hat{\theta}\\\hat{\phi}\end{pmatrix}=\begin{pmatrix}sin\theta cos\phi&sin\theta sin\phi&cos\theta\\cos\theta cos\phi&cos\theta sin\phi&-sin\theta\\-sin\phi&cos\phi&0\end{pmatrix}=\begin{pmatrix}\hat{i}\\\hat{j}\\\hat{k}\end{pmatrix}$$
The reverse transformation is given by \(M^{-1}S=M^{-1}MC\implies C=M^{-1}S\). Since the three spherical unit vectors are mutually perpendicular and have unit magnitude, the transformation matrix \(M\) is orthogonal. Therefore, \(M^{-1}=M^T\) and the reverse transformation is \(C=M^TS\):
$$\begin{pmatrix}\hat{i}\\\hat{j}\\\hat{k}\end{pmatrix}=\begin{pmatrix}sin\theta cos\phi&cos\theta cos\phi&-sin\phi\\sin\theta sin\phi&cos\theta sin\phi&cos\phi\\cos\theta&-sin\theta&0\end{pmatrix}=\begin{pmatrix}\hat{r}\\\hat{\theta}\\\hat{\phi}\end{pmatrix}$$
Expanding gives
$$\hat{i}=sin\theta cos\phi\hat{r}+cos\theta cos\phi\hat{\theta}-sin\phi \hat{\phi}$$
$$\hat{j}=sin\theta sin\phi\hat{r}+cos\theta sin\phi\hat{\theta}+cos\phi \hat{\phi}$$
$$\hat{k}=cos\theta\hat{r}-sin\theta\hat{\theta}$$