bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS Sticky Positioning

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind CSS Sticky Positioning?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___.sticky {
3Order

Put the learning moves in the order that makes the concept easiest to apply.

All CSS Positioning Properties
Common Uses for Sticky Positioning
CSS position: sticky

CSS position: sticky

An element with position: sticky; toggles between a relative and fixed position, depending on the scroll position.

A sticky element is positioned relative until a certain scroll position is reached - then it "sticks" in that place (like position:fixed).

Note

You must specify at least one of the top , right , bottom or left properties, for sticky positioning to work.

In this example, when the sticky element reach the top of the page (top: 0), it sticks to this position:

Example

Formatted code
div.sticky {
  position: sticky;
  top: 0;
  background-color: green;
  border: 2px solid #4CAF50;
}

Live preview

Common Uses for Sticky Positioning

Sticky positioning is commonly used for

  • Sticky headers - Navigation bars that stick to the top when scrolling
  • Sticky sidebars - Side content that stays visible while scrolling main content
  • Sticky table headers - Table headers that remain visible when scrolling long tables

Sticky vs. Fixed

The key differences between sticky and fixed positioning:

Featureposition: stickyposition: fixed
Initial behaviorActs like relativeAlways fixed to viewport
Space in documentTakes up space initiallyDoes not take up space
Scroll behaviorSticks after thresholdAlways fixed
Container boundYes, respects parent boundariesNo, always relative to viewport

All CSS Positioning Properties

PropertyDescription
bottomSets the bottom margin edge for a positioned box
clipClips an absolutely positioned element
leftSets the left margin edge for a positioned box
positionSpecifies the type of positioning for an element
rightSets the right margin edge for a positioned box
topSets the top margin edge for a positioned box

Previous

CSS Fixed and Absolute Positioning

Next

CSS Position Offsets