VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-position-sticky-top/

⇱ Bootstrap 5 Position Sticky Top - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Position Sticky Top

Last Updated : 1 May, 2024

Bootstrap 5 position-sticky class fixes an element at the top of the viewport when scrolling down. If not fully supported, alternatives like `position: fixed` or JavaScript solutions can mimic the sticky effect.

Position Sticky Top Class:

  • sticky-top: This class is used to set the position of the element to the sticky top of the viewport when users scrolls down the page.

Syntax:

<div class="sticky-top">
 Content
</div>

Examples of Bootstrap 5 Position Sticky Top

Example 1: In this example, we will create a div element of fixed width and height, and set its class to sticky-top to make the div sticky on the top of the page.

Output:

👁 Bootstrap-5-Position-Sticky-Top
Bootstrap 5 Position Sticky Top Example Output

Example 2: In this example, we will create an image element of fixed width and height, and set its class to sticky-top to make the image sticky on the top of the page.

Output:

👁 Bootstrap-5-Position-Sticky-Top
Bootstrap 5 Position Sticky Top Example Output
Comment

Explore