Website Building » Squarespace » How Do I Make a Sticky Header in Squarespace?

How Do I Make a Sticky Header in Squarespace?

Last updated on December 20, 2022 @ 6:08 pm

When you want to make a website stand out, one way to do so is by adding a “sticky” header. This means that when a user scrolls down the page, the header remains in the same spot at the top of the screen, making it easy for them to access the navigation menu or search bar.

Adding a sticky header in Squarespace is easy to do and only takes a few minutes. In this article, we’ll show you how to add a sticky header to your Squarespace website.

First, log in to your Squarespace account and go to the “Settings” tab. Next, click on the “Advanced” tab and scroll down to the “Code Injection” section. In the “Header” box, paste the following code:

<script>window.onscroll = function() {myFunction()};

var header = document.getElementById(“myHeader”);
var sticky = header.offsetTop;

function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add(“sticky”);
} else {
header.remove(“sticky”);
}
}</script>
This code will make sure that your header remains at the top of the screen when a user scrolls down your page.

Next, go to the “Design” tab and click on “Custom CSS”. In the box that appears, paste the following code:
#myHeader {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0; /* Add some top padding to the page content to prevent sudden quick movement (as the navigation bar gets a new position at the top of the page (position:fixed and top:0) */
padding-top: 50px; /* Add some top padding to the page content to prevent sudden quick movement (as the navigation bar gets a new position at the top of the page (position:fixed and top:0) */}

PRO TIP: While the instructions in the article may work for some people, others have found that following these steps can actually break their site. If you are not comfortable working with code, it is best to avoid making any changes to your site’s header.

/* Style the header links */

#myHeader a { /* Add a black background color with 70% opacity */}

#myHeader a.logo { /* Add an italic font style */}

#myHeader a:hover { /* Add a white background color with 70% opacity */ }

#myHeader .active { /* Add an underline style */}

#myHeader .container { /* Add padding around container */}

The code above will style your header so that it looks good on your website. Be sure to replace “#myHeader” with whatever you named your header tag in step 1.

That’s all you need to do! Now when you scroll down your Squarespace website, you’ll see that your header stays in place at the top of the screen.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.