Website Building » Squarespace » How Do I Make My Navigation Sticky in Squarespace?

How Do I Make My Navigation Sticky in Squarespace?

Last updated on December 23, 2022 @ 9:47 am

As you scroll down a Squarespace page, the fixed navigation bar stays at the top of the screen, making it easy for visitors to navigate your site. But what if you want to make your navigation bar “sticky” so it scrolls down with the page?

There are two ways to make your navigation bar sticky in Squarespace. The first is to use CSS code, and the second is to use JavaScript.

To use CSS code, go to Design > Custom CSS and add the following code:

#header {
position: fixed;
width: 100%;
z-index: 999;
}

This code will make your header fixed to the top of the screen, meaning it will scroll down with the page. You can also add other CSS properties to this code to change the look of your header, such as changing the background color or adding a border.

PRO TIP: If you are not familiar with coding, we do not recommend attempting to make your navigation sticky in Squarespace. Doing so could result in unforeseen issues with your site’s design and functionality.

To use JavaScript, go to Settings > Advanced > Code Injection and add the following code in the Header Code Injection box:

<script>
window.onscroll = function() {myFunction()};
var header = document.getElementById("header");
var sticky = header.offsetTop;
function myFunction() { if (window.pageYOffset > sticky) { header.classList.add("sticky"); } else { header.remove("sticky"); } } </script> <style> .sticky { position: fixed; top: 0; width: 100%;} .sticky + .content { padding-top: 102px;}</style>

This code will also make your header fixed to the top of the screen and will scroll down with the page. The difference between this code and the CSS code is that this code also adds a class to the header when it becomes sticky, which can be used to change the look of the header when it’s scrolled down (such as making the background color different).

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.