☰
ELEMENTOR / PRACTICE

How to Create Elementor Anchor Links Without Sticky Header Overlap

How to Create Elementor Anchor Links Without Sticky Header Overlap

When a user clicks a menu item, button, or another anchor link, the browser scrolls to the required element. If the top header uses position: sticky or position: fixed, it may cover the section heading. Instead of seeing the beginning of the required block, the user sees part of it hidden beneath the header.

You can fix this with the CSS property scroll-margin-top. It adds extra free space above the element the page scrolls to. The solution does not require separate JavaScript and works for navigation menus, buttons, and internal links.

Why a Sticky Header Covers the Target Section

An anchor link usually looks like #services and points to an element with the corresponding CSS ID. The browser finds this element and scrolls it to the top edge of the visible area. However, it does not always account for the height of a fixed or sticky header because the header does not occupy its usual space in the document flow.

As a result, the transition technically works correctly, but the top part of the section ends up beneath the header. This is especially noticeable when the target element is a heading or a container positioned at the very beginning of the section.

  • position: fixed completely removes the header from the normal document flow.
  • position: sticky keeps the element in the flow, but it may cover content while the page is scrolling.
  • The header height may differ on desktop, tablet, and mobile devices.
  • A regular margin-top on the section does not always solve the problem because it changes the layout rather than the position used when navigating to an anchor.

Preparing an Anchor in Elementor

First, identify the element that should appear beneath the header after the transition. Most often, this is a container or section with the required heading. Add the class used for scroll-margin-top to this element.

In the Elementor editor, open the required container or section and go to Advanced → CSS Classes. Add the class anchor-target without a dot at the beginning. The dot is used only in the CSS selector and should not be included in Elementor's class field.

If the transition uses an ID, also check the target element's CSS ID. For example, for the link #services, the element must have the ID services. The link uses the # symbol, while the CSS ID field usually contains only the value services.

  • Add anchor-target to the container that should be visible after the transition.
  • Do not add the class only to the button or menu item: these initiate the transition rather than serve as its target.
  • Make sure the ID is unique on the page.
  • If you use a separate Menu Anchor widget, add the class to the actual element the page scrolls to, or account for the position of this widget in your CSS.

The CSS Solution with scroll-margin-top

Add the CSS to a global site styles field: the theme's Custom CSS, Additional CSS in WordPress, or the appropriate global location in Elementor Pro. The style must load on the page where the anchors are placed.

The scroll-margin-top value should approximately match the actual header height. If the header is 90 px high, use the following code:

.anchor-target {
  scroll-margin-top: 90px;
}

Separate Values for Mobile Devices

On mobile devices, the header often has a different height: the logo size may change, a menu button may appear, or a different navigation version may be used. In this case, add a media query and specify a value that matches the mobile header.

@media (max-width: 767px) {
  .anchor-target {
    scroll-margin-top: 70px;
  }
}

How to Choose the Correct Offset

You do not have to choose the value at random. Open the page in a browser, determine the actual header height using the developer tools, and use it as your starting value. If there is additional space above the header or you want a small visual gap, add a few pixels.

For example, if the sticky header is 82 px high, you can start with scroll-margin-top: 82px or 90px. Then test the transition on the live page rather than only in the Elementor editor.

  • If the heading is partially covered, increase the value.
  • If too much empty space remains above the section after the transition, reduce the value.
  • Check each header type if its height changes while scrolling.
  • For the mobile version, test at least the width where the menu opens and the navigation height changes.

Checking the Anchor After Configuration

After adding the class and CSS, clear the cache for your caching plugin, CDN, and browser if they are in use. Elementor or CSS optimization may display an outdated version of the styles, making it seem as though the rule is not working.

Test every way of navigating to the section: the primary menu item, a button, a text link, and direct URL access with an anchor. In each case, the target element should remain below the header, and its heading should be fully readable.

  • Make sure the anchor-target class is present in the DOM.
  • Check whether the scroll-margin-top rule is being overridden by other CSS.
  • Make sure the link points to the correct ID rather than a duplicate or missing element.
  • Test the page outside the Elementor editor.
  • Check the desktop and mobile versions separately.

Common Mistakes and an Alternative Approach

One of the most common mistakes is adding scroll-margin-top to the link element instead of the target element. The property must be applied to the container or section identified by the ID.

You should also not add # to the value in the CSS Classes field. The correct sequence is: in Elementor, use the class anchor-target; in CSS, use .anchor-target.

If you need to apply the same top offset to all anchors across the site, you can style elements with IDs or use another shared selector. However, a separate class is safer: it does not affect unrelated elements and lets you configure only the required sections.

  • Do not replace this solution with large padding-top or margin-top values without checking responsiveness: this can disrupt the section's own spacing.
  • Do not use JavaScript when the standard CSS property is sufficient.
  • If an anchor points to an invisible element, such as a separate Menu Anchor, make sure the offset is applied to that element or to the correct container.
  • scroll-margin-top affects scrolling to the element but does not change its actual position in the layout.

When scroll-padding-top May Be Needed

If you control a scrollable container rather than the entire page, scroll-padding-top on that container may sometimes be more appropriate. For a standard WordPress page with anchors pointing to Elementor sections, scroll-margin-top on the target elements is usually the more practical and precise option.

Frequently asked questions

Does scroll-margin-top work with Elementor menus?

Yes. The important points are that the menu item must point to the correct ID and that the class containing scroll-margin-top must be added to the element serving as the transition target.

Do I need to add the anchor-target class to every section?

No. Add it only to the containers or sections targeted by anchor links and potentially covered by the sticky header.

Why did nothing change after I added the CSS?

Check the class, ID, and location where the CSS is loaded. Also clear the browser cache, optimization plugin cache, and generated styles if they are being used.

What scroll-margin-top value should I choose for the mobile version?

Measure the height of the mobile header and use it as a reference. If it differs from the desktop height, set a separate value with a media query.

Do I need Elementor Pro for this solution?

No. You only need a way to add a class to the element and add global CSS. Depending on your configuration, this can be done through the theme's Additional CSS field or another global CSS mechanism.

Conclusion

To prevent Elementor anchor links from being hidden beneath a sticky header, add the anchor-target class to the target container and apply scroll-margin-top to it. The value should match the header height, and it is best to configure a separate value for mobile devices.

Afterward, check the ID, every type of link, responsive versions, and caching. For most WordPress pages, this CSS solution is enough to make navigation to sections predictable and convenient for users.

← All Elementor materials