Draw a rectangle inside margins

I am new to LaTeX and I am trying to place a rectangle (filled in red for instance) at the very top of all the pages of my document. The rectangle should be 0.5 cm high and with the page width.

I saw a lot of complicated threads to do that, but cannot manage to reproduce it.

My basic attempt by drawing a rectangle with \tikzpicture:

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\fill[red] (0,0) rectangle (\paperwidth, 0.5cm)
\end{tikzpicture}
\end{document}


The problem is that LaTeX only starts drawing at the top left corner of the margin and not of the page. I tried to use \voffset but nothing changes.

Welcome to TeX SX! You don't really need TikZ for that: a simple coloured \rule will do, and the eso-pic package will let you insert what you want at any position in the page:

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{article}
\usepackage[texcoord]{eso-pic}
\usepackage[showframe]{geometry}
\usepackage{lipsum}