Hide Header on Scroll for Squarespace
A hide on scroll header keeps navigation out of the way while people read, then brings it back the moment they scroll up. This free Squarespace hide header on scroll snippet uses a small piece of vanilla JavaScript to watch scroll direction and a CSS transition to slide the header away smoothly. It ignores tiny scroll jitters so the header does not flicker, and it works with the standard Squarespace 7.1 fixed header. No plugin required, just paste and publish.
The Code
/* Slide the header out of view when the script adds .header-hidden */
#header {
transition: transform 0.3s ease;
}
#header.header-hidden {
transform: translateY(-100%);
}<script>
(function () {
var header = document.getElementById('header');
if (!header) return;
var lastY = window.scrollY;
var ticking = false;
function onScroll() {
var y = window.scrollY;
/* Ignore jitters smaller than 10px so the header does not flicker */
if (Math.abs(y - lastY) > 10) {
if (y > lastY && y > 120) {
header.classList.add('header-hidden'); /* scrolling down */
} else {
header.classList.remove('header-hidden'); /* scrolling up */
}
lastY = y;
}
ticking = false;
}
window.addEventListener('scroll', function () {
if (!ticking) {
window.requestAnimationFrame(onScroll);
ticking = true;
}
}, { passive: true });
})();
</script>How to Install It
- 1Enable a fixed header so the effect is visible: click Edit on any page, hover the header, choose Edit Site Header, open the Style settings, and turn on Fixed Position (Basic).
- 2Go to Design > Custom CSS (Website Tools > Custom CSS on newer dashboards), paste the CSS block, and save.
- 3Go to Settings > Advanced > Code Injection (Website Tools > Code Injection on newer dashboards), paste the JavaScript block into the Footer field, and save.
- 4Preview any page: scroll down and the header slides away, scroll up and it returns.
Compatibility and Plan Requirements
Squarespace 7.1. Needs a fixed header (Fixed Position in the header style settings) for the effect to be visible. The #header id is standard in 7.1 but can differ on heavily customized templates.
This snippet uses JavaScript, which Squarespace only runs through code injection or code blocks on the Business plan or higher. On Personal plans the script will not execute.
More Squarespace Snippets
View allWant This Done For You?
If you would rather not touch code, or you need something bigger than a snippet, I build custom Squarespace features for clients every week: widgets, search and filter tools, integrations, and full sites.