Skip to content

Transparent Navbar that Turns Solid on Scroll

Bootstrap 5 navbar that sits transparently over a gradient hero and becomes a solid, blurred bar with a shadow when the page scrolls.

Also known as: transparent navbar on scroll, sticky navbar changes on scroll, navbar over hero image, fixed header scroll effect

Bootstrap 5 Navbars Responsive #hero #navbar #scroll #sticky #transparent

Transparent Navbar that Turns Solid on Scroll live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 navbar that sits transparently on top of a full-screen gradient hero and turns into a solid, blurred bar with a soft shadow once the visitor scrolls. It suits landing pages, product sites and portfolios where the first screen should feel open but the navigation must stay readable further down.

How it works

The navbar is a nav.navbar.navbar-expand-lg.fixed-top.tn-nav with a brand, a collapsible link list and a .tn-cta button. Below it, .tn-hero fills the viewport (min-height: 100svh) with layered radial and linear gradients and a faded grid pattern drawn by .tn-hero::after. Three demo sections follow so the page is tall enough to scroll; every element with an id gets scroll-margin-top, so anchor links do not end up under the fixed bar.

The markup ships with .tn-nav--solid and data-bs-theme="light", so the bar is readable even without JavaScript. On DOMContentLoaded the script reads data-tn-offset and listens to scroll (passive, throttled with requestAnimationFrame). Past the offset it adds .tn-nav--solid and sets data-bs-theme="light"; at the top it removes the class and switches to data-bs-theme="dark", which gives white links and a white toggler icon through Bootstrap's own color modes. .tn-nav--ready is added after the first paint so the bar does not fade on page load. The script also listens to show.bs.collapse and hidden.bs.collapse, keeping the bar solid while the mobile menu is open, and closes the menu with bootstrap.Collapse.getOrCreateInstance() after a link is chosen.

Customization

  • data-tn-offset="48" on .tn-nav: set how many pixels the page scrolls before the bar turns solid; use 0 to switch immediately.
  • --tn-solid-bg in .tn-nav: change the scrolled background, e.g. rgba(15, 23, 42, 0.9) for a dark bar; then change 'light' to 'dark' in the script's update() function so the links stay white.
  • --tn-shadow in .tn-nav: make the shadow stronger, or set it to none for a flat bar.
  • --tn-accent and --tn-accent-hover in .tn-nav: recolor the .tn-cta button and the logo in the solid state.
  • --tn-hero-from, --tn-hero-via and --tn-hero-to in .tn-hero: change the three gradient stops of the hero background.
  • --tn-transition in .tn-nav: speed up or slow down the background, shadow and padding change.
  • padding-block in .tn-nav and .tn-nav--solid: control how much the bar shrinks when it becomes solid.

Use cases

  • Landing pages: the bar sits transparently over a full-screen gradient hero, then turns solid on scroll
  • Product sites: a blurred, shadowed bar keeps links readable further down the page
  • Portfolios: anchor links scroll to sections without ending up under the fixed navbar
  • Mobile menus: the bar stays solid while the collapsed menu is open

Accessibility

The nav has aria-label="Main navigation", the current link uses aria-current="page" and the script moves it to the link that was clicked. The toggler keeps Bootstrap's aria-controls, aria-expanded and label. Nav links, the brand and the call-to-action get a visible outline on :focus-visible in both states. Link colors over the hero are raised to 85% white for better contrast. With prefers-reduced-motion: reduce the bar transition and the bouncing scroll hint are disabled. The decorative SVGs are aria-hidden.

Usage notes

Requires Bootstrap 5.3 or newer for data-bs-theme. Remove the demo sections and keep .tn-nav and .tn-hero in your layout.

Transparent Navbar that Turns Solid on Scroll at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5
Layout
Responsive, works on mobile
Category
Navbars
License
Free for personal and commercial use

Questions about this template

Can I use the Transparent Navbar that Turns Solid on Scroll code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
Transparent Navbar that Turns Solid on Scroll – free Bootstrap 5 navbar template
Transparent Navbar that Turns Solid on Scroll · free Bootstrap 5 navbar template

More Navbars

Navbar with Sliding Active Indicator – free Pure CSS navbar template

Navbar with Sliding Active Indicator

Dark responsive navbar with a glowing underline that slides between links on hover, focus and click, built with CSS custom properties and vanilla JS.

Navbar with Offcanvas Drawer on Mobile – free Bootstrap 6 navbar template

Navbar with Offcanvas Drawer on Mobile

Responsive Bootstrap 6 navbar that shows inline links on desktop and moves them into a slide-in Drawer with icons, studio hours and social links on small screens.

Navbar with Overflow Menu (NavOverflow) – free Bootstrap 6 navbar template

Navbar with Overflow Menu (NavOverflow)

Bootstrap 6 news navbar built on the new NavOverflow component: links that do not fit move into a More menu automatically as the width shrinks.

Navbar with Centered Logo – free Tailwind CSS navbar template

Navbar with Centered Logo

Dark Tailwind CSS navbar with links split around a centered logo, animated underlines and an accessible slide-down mobile menu.