This is a quick 'n' dirty example based on fancyhead gradient doesn't match bg colour. To be honest, I do not fully understand the code. 0.01 is the thickness (in cm) on the headrule and 14.98 is the length (in cm).
The important part is that you can re-define fancyhdr's \headrule
command with some tikz magic.
At least, you can use the code as a basis for your own experiments and as a basis for a potential follow-up question (see here).
\documentclass{article}
\usepackage{blindtext}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{tikz}
% https://tex.stackexchange.com/questions/241738
\renewcommand{\headrule}{%
\vskip-\baselineskip\vskip4pt
\hfill\begin{tikzpicture}
\shade[left color=white, right color=blue, dashed] (0,0) rectangle (14.98,0.01);
\end{tikzpicture}
}
\begin{document}
\blinddocument
\end{document}
