HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Learn how to create a sticky element with CSS
div.sticky {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
}
Try it Yourself »
An element with position: sticky;
is positioned based on the user's scroll position.
A sticky element toggles between relative
and fixed
, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).
Note: Internet Explorer, Edge 15 and earlier versions do not support sticky positioning. Safari requires a -webkit-
prefix (see example below). You must also specify at least one of top
, right
, bottom
or left
for
sticky positioning to work.
To learn more about CSS positoning, read our CSS Position tutorial.