🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #70

Sticky Position


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

div.sticky {
  position:
  sticky;
  top: 0;
  background-color: green;

  border: 2px solid #4CAF50;
}

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:

Feature position: sticky position: fixed
Initial behavior Acts like relative Always fixed to viewport
Space in document Takes up space initially Does not take up space
Scroll behavior Sticks after threshold Always fixed
Container bound Yes, respects parent boundaries No, always relative to viewport

All CSS Positioning Properties

Property Description
bottom Sets the bottom margin edge for a positioned box
clip Clips an absolutely positioned element
left Sets the left margin edge for a positioned box
position Specifies the type of positioning for an element
right Sets the right margin edge for a positioned box
top Sets the top margin edge for a positioned box

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Sticky Position – FAQs

Quick answers about learning Sticky Position in CSS.

This free note from CodingNow 2.0 explains Sticky Position in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Sticky Position, is 100% free with no signup required.
With focused practice, most students grasp Sticky Position in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now