Elementor sticky header anchor offset is a fix for menu links that scroll headings underneath a sticky header. Elementor’s free version has no anchor offset setting, so on a one-page site the browser scrolls each section to the very top, where the sticky header covers it. The fix is a short JavaScript snippet that offsets the scroll by your header’s height, with separate values for desktop and mobile.
When using Elementor Page Builder, it’s common to use sticky header, especially if you are designing a landing page that works as a one-page site.
One-page sites have navigation menu items that auto-scroll users to the anchor links on the same page.
These are links that start with a hash sign followed by the ID (#id).
If the header is not sticky, it’s very easy to implement this by adding id attributes to each sub section and corresponding menu items with hashtags.
That’s where it gets tricky: once the header is sticky, the auto-scroll needs an offset equal to the header’s height.
How to use WordPress Playground for testing a one-page website with Elementor
You can test a one-page Elementor site in WordPress Playground, which runs WordPress in your browser without a server, domain or hosting account. The Playground link below installs everything this tutorial needs, so you can follow each step and try the snippet before adding it to a live site.
To demonstrate this, let’s implement a basic one-page site using WordPress Playground.
It runs on WebAssembly, so there’s nothing to install or configure, and it’s just as handy for testing any other plugin or theme.

Skip Elementor’s default onboarding and continue as Guest.
The WordPress Playground link above auto installs Hello Elementor theme together with Elementor and Ultimate Addons for Elementor (which is required for navigation menu) in the free version.
How to implement sticky header with only CSS using Elementor
You can make an Elementor header sticky with only CSS, without Elementor Pro, by adding a CSS class to the header section and a few lines of Additional CSS in the Customizer. The steps below set up the header, the menu and the section IDs that the anchor links will point to.
To demonstrate the one-page site, simply add a few sections and rename the top most section as Header.
Navigate to Advanced > CSS Classes section and add sticky-header to the class list. Later, we will add Additional CSS to make the header sticky.
Next, navigate to Appearance > Menus. Create a new menu as seen in the screenshot with custom links to anchors on the same page (e.g. #sub1, #sub2, #sub3)

Next, navigate to Appearance > Customize and paste the following CSS styles to the Additional CSS textbox.
.sticky-header {
position: sticky;
top: 0;
z-index: 9999;
}
.admin-bar .sticky-header {
top: 30px;
}
Your header section should now become sticky.
If you haven’t added sub sections, just add a few to increase the page height, so that you can test whether header sticks to the top when scrolling.
Finally, add the CSS IDs to the section headings to target them from the navigation menu items we added.

Why sticky header needs anchor offset
A sticky header needs an anchor offset because the browser scrolls a clicked section until its heading reaches the very top of the screen, where the sticky header then covers it. The offset tells the browser to stop scrolling earlier, by the height of your header.
If you have implemented the design features we have added so far, you should be able to click menu items and navigate between sub sections.
Try it: click a sub heading in the menu and the sticky header ends up covering it.
Elementor (free version) doesn’t have a Menu Anchor widget that allows you to add scroll offset with a configurable height.
So, we need to add custom JavaScript to the end of the page in order to override the default behavior of Elementor and customize the offset height according to your custom header height for Desktop and Mobile views.
Add custom JavaScript for configuring anchor offset
You can add an anchor offset in Elementor with a short custom JavaScript snippet placed in an HTML widget at the end of the page. It stops the scroll at a set distance from the top, with separate values for desktop and mobile, so headings no longer hide under the sticky header.
In this final section of the tutorial, we’ll add that HTML widget and the snippet itself.
Here is a short video after adding the custom JS.
Open your Elementor editor and add the following snippet to the bottom of the page using the HTML widget.
<script>
(function() {
const SCROLL_OFFSET_DESKTOP = 150; // px to offset from top on desktop
const SCROLL_OFFSET_MOBILE = 120; // px to offset from top on mobile
const MOBILE_BREAKPOINT = 768; // px
const SCROLL_DURATION = 800; // ms
function getScrollOffset() {
return window.innerWidth <= MOBILE_BREAKPOINT ? SCROLL_OFFSET_MOBILE : SCROLL_OFFSET_DESKTOP;
}
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('click', function(e) {
const link = e.target.closest('a[href*="#"]');
if (!link) return;
const href = link.getAttribute('href');
const hashIndex = href.indexOf('#');
if (hashIndex === -1) return;
const targetId = href.substring(hashIndex + 1);
if (!targetId) return;
const targetEl = document.getElementById(targetId) ||
document.querySelector(`[data-id="${targetId}"]`) ||
document.querySelector(`.elementor-element[data-id="${targetId}"]`);
if (!targetEl) return;
// Stop Elementor's own scroll handler and default jump
e.preventDefault();
e.stopImmediatePropagation();
closeMobileMenu();
const targetPosition = targetEl.getBoundingClientRect().top + window.pageYOffset - getScrollOffset();
smoothScrollTo(targetPosition, SCROLL_DURATION);
// Update the URL hash without triggering another jump
history.pushState(null, null, '#' + targetId);
}, true); // capture phase, so this runs BEFORE Elementor's own bubble-phase listener
});
function closeMobileMenu() {
// --- Universal detection: check if the mobile nav panel is actually visible on screen ---
var navWidgets = document.querySelectorAll('.elementor-widget-navigation-menu');
navWidgets.forEach(function(widget) {
// The dropdown panel is a child <ul> or container inside the widget
var navPanel = widget.querySelector('.hfe-nav-menu, ul[class*="nav-menu"]');
if (!navPanel) return;
var rect = navPanel.getBoundingClientRect();
var style = window.getComputedStyle(navPanel);
var isVisible = style.display !== 'none' &&
style.visibility !== 'hidden' &&
rect.height > 0 &&
navPanel.offsetParent !== null;
if (isVisible && window.innerWidth <= 1024) {
var toggle = widget.querySelector(
'.hfe-nav-menu-icon, .hfe-nav-menu-icon-wrapper, [class*="menu-icon"], [class*="menu-toggle"], [aria-label*="menu" i], [aria-label*="toggle" i]'
);
if (toggle) {
toggle.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
}
}
});
// --- Attribute-based fallbacks (in case icon-specific markup does expose these) ---
document.querySelectorAll('.hfe-nav-menu-icon-wrapper[aria-expanded="true"], .hfe-nav-menu-icon[aria-expanded="true"]').forEach(function(btn) {
btn.click();
});
document.querySelectorAll('.hfe-nav-menu-icon-wrapper.toggled, .hfe-nav-menu-icon.toggled').forEach(function(btn) {
btn.click();
});
// --- Classic Nav Menu widget ---
document.querySelectorAll('.elementor-menu-toggle[aria-expanded="true"]').forEach(function(btn) {
btn.click();
});
// --- Newer "Nav Menu" widget (Elementor 3.6+, e-n-menu) ---
document.querySelectorAll('.e-n-menu-toggle[aria-expanded="true"]').forEach(function(btn) {
btn.click();
});
document.querySelectorAll('.e-n-menu-heading[aria-expanded="true"]').forEach(function(btn) {
btn.click();
});
// --- Hello Theme header (theme-native mobile menu) ---
document.querySelectorAll('.site-header-mobile-toggle[aria-expanded="true"]').forEach(function(btn) {
btn.click();
});
// Give click handlers a tick to run before checking fallback state
setTimeout(function() {
// Fallback: strip common "open" markers directly if click-through didn't close it
var openSelectors = [
'.hfe-nav-menu.toggled',
'.hfe-nav-menu-wrapper.toggled',
'.elementor-nav-menu--dropdown.elementor-active',
'.e-n-menu.e--pointer-click.e-active',
'.e-n-menu[data-open="true"]',
'.elementor-active.elementor-nav-menu__container'
];
openSelectors.forEach(function(sel) {
document.querySelectorAll(sel).forEach(function(el) {
el.classList.remove('elementor-active', 'e-active');
el.removeAttribute('data-open');
});
});
document.querySelectorAll('[aria-expanded="true"]').forEach(function(btn) {
// Only touch elements that look like menu toggles, to avoid unrelated aria-expanded elements
if (btn.className && /menu|toggle|hamburger|hfe/i.test(btn.className)) {
btn.setAttribute('aria-expanded', 'false');
btn.classList.remove('elementor-active', 'e-active', 'toggled');
}
});
// Restore scroll lock
document.body.classList.remove('elementor-nav-menu--dropdown-open');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
}, 50);
}
function smoothScrollTo(targetY, duration) {
const startY = window.pageYOffset;
const distance = targetY - startY;
let startTime = null;
function animation(currentTime) {
if (startTime === null) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const progress = Math.min(timeElapsed / duration, 1);
const ease = easeInOutCubic(progress);
window.scrollTo(0, startY + distance * ease);
if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
}
function easeInOutCubic(t) {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
requestAnimationFrame(animation);
}
})();
</script>
Adjusting the offset amount for desktop and mobile
You can set different anchor offsets for desktop and mobile by changing the constants at the top of the snippet. The offset values are in pixels and should match your sticky header’s height on each screen size, while the breakpoint and scroll duration are optional.
At the top of the snippet, you’ll see 4 constants:
SCROLL_OFFSET_DESKTOP(pixels)SCROLL_OFFSET_MOBILE(pixels)MOBILE_BREAKPOINT(pixels)SCROLL_DURATION(milliseconds)
Change the default value of 150 for the SCROLL_OFFSET_DESKTOP according to your sticky header’s height.
Similarly change the value of SCROLL_OFFSET_MOBILE if your mobile header is shorter than the desktop header. This usually happens when you reduce the logo size for the mobile view.
Adjusting MOBILE_BREAKPOINT and SCROLL_DURATION are optional. These are self explanatory parameters. You can change the mobile breakpoint if needed and speed up or slow down the scrolling duration.
Additional info
The snippet closes the mobile menu after a menu item is tapped, because overriding Elementor’s default scroll behavior would otherwise leave it open. This keeps the mobile experience the same as a normal Elementor menu on phones and tablets, as explained below.
If you carefully go through the custom JS code we have added, there is a function closeMobileMenu()
It runs as soon as a menu item is clicked, so visitors see the section they picked straight away instead of an open menu.
Why use Ultimate Addons for Elementor (formerly Header Footer Elementor)
Ultimate Addons for Elementor adds the widgets this tutorial needs that Elementor’s free version doesn’t include, such as a WordPress navigation menu. It’s free, available on WordPress.org, and also helps keep the Elementor editor lean by letting you turn off widgets you don’t use.
Free Elementor can’t make a section sticky either, which is why we used CSS for the header earlier in this tutorial.
There are a bunch of add-on plugins that provide additional widgets including the navigation menu, but Ultimate Addons for Elementor plugin also allows you to imitate the Theme Builder functionality of Elementor Pro.
Turning off the widgets you don’t use also avoids loading unnecessary code.
If you’re fine-tuning your Elementor pages further, check your hero image too. Elementor sometimes misjudges which images are above the fold and adds loading="lazy" to the hero image, which delays Largest Contentful Paint (LCP). Our Elementor LCP fix shows how to remove lazy loading from that image and set fetchpriority="high" instead.
Conclusion
The key takeaway is that Elementor’s default smooth scrolling overrides the usual CSS methods for anchor offsets, so custom JavaScript is needed in this setup. Below are the three CSS methods I tested, and why none of them worked with Elementor’s default scrolling.
Using modern CSS, adding anchor offsets is actually very easy using one of the methods below:
Global scroll padding for all anchor links
Global scroll padding is a CSS method that offsets every anchor link on the page at once, using scroll-padding-top on the html element. It’s the simplest way to add an anchor offset for a sticky header in plain CSS, with a single rule.
html {
scroll-padding-top: 100px;
}Adjusting individual scroll margins
Individual scroll margins are a CSS method that sets the offset on each target element with scroll-margin-top, so different sections can stop at different heights. They’re useful when some sections need more space below the header than others on the same page.
#elementor-section-id {
scroll-margin-top: 100px;
}Unfortunately, default smooth scroll behavior of Elementor overrides both CSS and it requires custom JavaScript code to achieve the functionality we need.
Using target pseudo selector
The :target pseudo selector is a CSS method that styles only the element a URL hash points to. It can be used to add space above a linked section, so the sticky header doesn’t cover it after the page scrolls to that section.
There is a final solution I’ve seen when searching for the solution of this issue, which can be implemented with the following CSS Code.
:target {
scroll-margin-top: 100px;
}However, this didn’t work in my case as well as the previous two CSS styles, even though I tried using the !important keyword.
If you need help implementing this Elementor trick, or similar visual tweaks and improvements, check out our Pricing page, or contact us for a free consultation with a WordPress expert.




