Skip to main content
CSS Tip

Calculate the scroll progress of the page

Get the scroll progress of the page as a CSS variable using a few lines of code

@property --s {
syntax: '<integer>';
inherits: true;
initial-value: 0;
}
:root {
animation: scroll 1s linear;
animation-timeline: scroll();
}
@keyframes scroll {
to {--s: 100}
}

element:before {
content: counter(s) "%";
counter-reset: s var(--s);
}

See the Pen CSS only scroll progress by Temani Afif (@t_afif) on CodePen.


More CSS Tips