CSS Position

Fixed

Fixed positioning is almost identical to absolute positioning except that it does not look for the nearest positioned ancestors, but rather immediately positions relative to the visible part of the viewport. This is useful for elements that must have the same position regardless of scroll position.

Code and Preview

Description

Notice here how the fixed positioned element (star inside the green box) is positioned relative to the visible part of the viewport and is always in the top left corner no matter how much we resize the window or scroll to diffent positions.

Try scrolling up and down in the preview frame.

Editor
Preview