Fig. 1 Shows a cartesian coordinate system that has been rotated keeping the origin fixed. The original (unprimed) system has basis vectors {$\mathbf{i}, \mathbf{j}, \mathbf{k}$}. The rotated (primed) system has basis vectors {$\mathbf{i}^{\prime},\mathbf{j}^{\prime}, \mathbf{k}^{\prime}$}. Under the rotation transformation the position vector $\mathbf{r}$ is unchanged however its components are different in the two systems. The vector $\mathbf{r}$ in the original system is given by
$$\mathbf{r}=x\mathbf{i}+y\mathbf{j}+z\mathbf{k}$$
and in the rotated system it is
$$\mathbf{r}=x^{\prime}\mathbf{i}^{\prime}+y^{\prime}\mathbf{j}^{\prime}+z^{\prime}\mathbf{k}^{\prime}$$
Hence we may write
$$x^{\prime}\mathbf{i}^{\prime}+y^{\prime}\mathbf{j}^{\prime}+z^{\prime}\mathbf{k}^{\prime}=x\mathbf{i}+y\mathbf{j}+z\mathbf{k}$$
To find the relationship between the primed components and the unprimed components we take the dot product of both sides of the last equation with $\mathbf{i}^{\prime}$ remembering that
$$\mathbf{i}^{\prime}\cdot\mathbf{i}^{\prime}=1$$
$$\mathbf{j}^{\prime}\cdot\mathbf{i}^{\prime}=0$$
$$\mathbf{k}^{\prime}\cdot\mathbf{i}^{\prime}=0$$
$$\mathbf{i}\cdot\mathbf{i}^{\prime}=a_{xx^{\prime}}$$
$$\mathbf{j}\cdot\mathbf{i}^{\prime}=a_{xy^{\prime}}$$
$$\mathbf{k}\cdot\mathbf{i}^{\prime}=a_{xz^{\prime}}$$
Where the $a$ values are the direction cosines for example $a_{xx^{\prime}}$ is the cosine of the angle between the $x$ and $x^{\prime}$ axes. When we take the dot product we get
$$x^{\prime}=a_{xx^{\prime}}x+a_{xy^{\prime}}y+a_{xz^{\prime}}z$$
Similarly by taking the dot product of both sides with $\mathbf{j}^{\prime}$ we get
$$y^{\prime}=a_{yx^{\prime}}x+a_{yy^{\prime}}y+a_{yz^{\prime}}z$$
and finally taking the dot product of both sides with $\mathbf{k}^{\prime}$ gives
$$z^{\prime}=a_{zx^{\prime}}x+a_{zy^{\prime}}y+a_{zz^{\prime}}z$$
The last three equations may be written compactly in matrix notation viz
$$\begin{pmatrix}x^{\prime}\\y^{\prime}\\z^{\prime}\end{pmatrix}=\begin{pmatrix}a_{xx^{\prime}}&a_{xy^{\prime}}&a_{xz^{\prime}}\\a_{yx^{\prime}}&a_{yy^{\prime}}&a_{yz^{\prime}}\\a_{zx^{\prime}}&a_{zy^{\prime}}&a_{zz^{\prime}}\end{pmatrix}\begin{pmatrix}x\\y\\z\end{pmatrix}$$
Calling the matrix of direction cosines $A$ we may write
$$\mathbf{r}^{\prime}=A\mathbf{r}$$
Where $A$ is an orthogonal matrix (transpose equals inverse). Multiplying both sides of the last equation by $A^{\mathbin{-}1}=A^T$ we get
$$A^T\mathbf{r}^{\prime}=A^{\mathbin{-}1}A\mathbf{r}=I\mathbf{r}=\mathbf{r}$$
so the inverse transformation from unprimed to primed system is
$$\mathbf{r}=A^T\mathbf{r}^{\prime}$$
Now we introduce a switch in notation. Instead of calling our axes $x$, $y$ and $z$ we call them $x_1$, $x_2$ and $x_3$. We may now rewrite our transformation equations as
$$x_1^{\prime}=a_{11}x_{1}+a_{12}x_{2}+a_{13}x_{3}=a_{1j}x_{j}$$
$$x_2^{\prime}=a_{21}x_{1}+a_{22}x_{2}+a_{23}x_{3}=a_{2j}x_{j}$$
$$x_3^{\prime}=a_{31}x_{1}+a_{32}x_{2}+a_{33}x_{3}=a_{3j}x_{j}$$
Where we have made use of Einstein’s summation convention. These three equations may be combined into the single succinct equation given below.
$$x_i^{\prime}=a_{ij}x_{j}$$
In this equation setting $i=1, 2, 3$ in turn generates the three equations. $i$ appears on both sides of the equation and is called a free index. $j$ is just a dummy index that is summed over.
Taking the partial derivative with respect to $x_k$ of both sides gives us
$$\frac{\partial x_i^{\prime}}{\partial x_k}=a_{ij}\frac{\partial x_j}{\partial x_k}=a_{ij}\delta_{jk}=a_{ik}$$
relabeling $k$ as $j$ gives
$$\frac{\partial x_i^{\prime}}{\partial x_j}=a_{ij}$$
Thus the vector transformation law may be written
$$x_i^{\prime}=\frac{\partial x_i^{\prime}}{\partial x_j}x_j$$
This is called the contravariant vector transformation law and position vectors obey it. Thus position vectors are contravariant vectors.
The equation for $\mathbf{r}$ in terms of $\mathbf{r^\prime}$ may be rewritten as
$$x_i=a_{ij}^Tx_{j}=a_{ji}x_j$$
Differentiating both sides with respect to $x_k^{\prime}$ gives
$$\frac{\partial x_i}{\partial x_k^{\prime}}=a_{ji}\frac{\partial x_j^{\prime}}{\partial x_k^{\prime}}=a_{ji}\delta_{jk}=a_{ki}$$
relabeling $k$ as $j$ gives
$$\frac{\partial x_j}{\partial x_i^{\prime}}=a_{ij}$$
Thus we may write the vector transformation law from unprimed to primed coordinates as
$$x_i^{\prime}=\frac{\partial x_j}{\partial x_i^{\prime}}x_j$$
This is called the covariant vector transformation law and gradient vectors obey it. We now show this and thus prove that gradient is a covariant vector. We start with
$$a_{ij}=\frac{\partial x_j}{\partial x_i^{\prime}}$$
multiplying both sides by $\frac{\partial\phi}{\partial x_j}$ where $\phi$ is a scalar function we get using the chain rule
$$\frac{\partial\phi}{\partial x_j}a_{ij}=\frac{\partial\phi}{\partial x_j}\frac{\partial x_j}{\partial x_i^{\prime}}=\frac{\partial\phi}{\partial x_i^{\prime}}$$
Thus
$$\frac{\partial\phi}{\partial x_i^{\prime}}=\frac{\partial x_j}{\partial x_i^{\prime}}\frac{\partial\phi}{\partial x_j}$$
Now the partial derivatives involving $\phi$ are the components of gradient in the primed and unprimed system so this proves gradient is covariant vector obeying the covariant vector transformation law.