![]() |
VOOZH | about |
Bootstrap 5 Scrollspy in Navbar is used to apply the Scrollspy on the Navbar. If you want to shift your active navbar item throughout the scrolling then this will be helpful.
Pre-requisite: Bootstrap-5 Scrollspy and Bootstrap-5 Navbar.
There is no predefined class for all the things you need to create Scrollspy in Navbar is covered Scrollspy & Navbar components.
<body data-bs-spy="scroll" data-bs-target="#..">
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#GFG">GFG1</a>
</li> . . .
</ul>
</nav>
...
</body>
Example 1: Below example is about scrollspy and how the active classes change when we scroll the content.
Output:
Example 2: In the below example we have implemented scrollspy using a scrollable container.
Output: