Every Mother

Keeping a Parent Navigation Link Active on CMS Pages in Webflow

K

One common UX issue with CMS-driven blogs in Webflow is this:

You have a top-level navigation link like Insights that points to /insights, but when you’re on an individual CMS post (for example /insights/post-name), the parent Insights link is no longer highlighted as active.

From a user experience standpoint, that’s not ideal. Visitors should always know which section of the site they’re in.

An example of a blog post that doesn't have an active state on the CMS Blog pages.
Note that the child page of Insights (all blog pages) does not make Insights turn blue (add active state) in the navigation.

Why Webflow Doesn’t Handle This Automatically

Webflow applies the w--current class only when the link URL exactly matches the current page URL.

That works for:

  • /about
  • /contact

But not for CMS structures like:

  • /insights
  • /insights/post-title

Because those are technically different URLs, Webflow doesn’t treat them as the same section.


The Fix: Add the Active Class Based on the URL

I solved this by adding a small vanilla JavaScript snippet in the Before </body> section of the page settings.

Here’s the script:

<script>
window.addEventListener("load", function () {

  var currentPath = window.location.pathname.replace(/\/$/, "");

  // Scope to links inside the nav menu only
  var menuLinks = document.querySelectorAll(".w-nav-menu a.nav-link");

  menuLinks.forEach(function(link) {

    var linkPath = new URL(link.href).pathname.replace(/\/$/, "");

    // Ignore home or empty paths
    if (!linkPath || linkPath === "/") return;

    // Match exact section or child pages only
    var isMatch =
      currentPath === linkPath ||
      currentPath.startsWith(linkPath + "/");

    if (isMatch) {
      link.classList.add("w--current");
      link.setAttribute("aria-current", "page"); // improves accessibility
    }

  });

});
</script>

What This Does

  • Looks at the current page URL.
  • Loops through all navigation links.
  • Checks whether the current URL starts with the link’s URL.
  • If it does, it manually adds Webflow’s active class: w--current.

So now:

  • /insights
  • /insights/financial-wellness
  • /insights/any-future-post

All correctly highlight the Insights nav link.

Image showing a blog post from the Webflow CMS having the parent link active.
After inclusion of javascript in footer, the parent link is blue showing the active class.

Why We Put It Before </body> – Footer Code

You’ll find that this script does not work when you place it in the <head>.

That’s because the navigation hasn’t loaded yet when the script runs. When working with Webflow components, symbols, or dynamic content, timing matters.

Placing it before </body> ensures:

  • The DOM is fully loaded.
  • The nav links exist.
  • The script can safely modify them.

If you prefer placing the script in the <head> you’ll use <script defer> . Including defer ensures the script waits to run until the page is parsed.


Always Double-Check Your Nav Classes

One important step when using this approach is to inspect your navigation and confirm which classes are actually being used.

In my case:

  • The nav menu I’m targeting is w-nav-menu
  • The navigation links use the class nav-link
  • The active state class applied by Webflow is w--current

Your project may be different. Some templates or designers rename classes, and navigation links might be called:

  • nav-item
  • menu-link
  • navbar-link
  • or something custom

If the selector in your script doesn’t match the real class on your links, nothing will happen.

How to Check

  1. Right-click a navigation link in your published site.
  2. Choose Inspect.
  3. Look at the <a> tag and note:
    • The class used on the link
    • The class applied when the link is active

Then update the script accordingly:

document.querySelectorAll('.your-class-here')

and, if needed:

link.classList.add("your-active-class");

Will the Active Class Always Be w--current?

If you’re using Webflow’s built-in navigation and link settings, the active class will almost always be w--current, because that’s what Webflow uses internally.

However, designers and developers sometimes:

  • Remove default styling
  • Use custom active states
  • Or rely on a different class for styling

So it’s always worth confirming instead of assuming.


A Good Reminder: Inspect First, Assume Nothing

If there’s one lesson in this process, it’s this: always inspect before you troubleshoot.

Visual builders make it easy to forget that, underneath the interface, you’re still working with HTML, CSS, and JavaScript. Classes may not be what you expect. Elements may load later than you think. And behaviors that seem automatic often rely on very specific conditions behind the scenes.

Taking a few seconds to open your browser’s developer tools, inspect the element, and confirm what’s actually happening can save a lot of frustration. It turns guesswork into problem-solving.

In my experience, the developers and designers who move fastest aren’t the ones who memorize the most tricks…they’re the ones who verify what’s really happening before they try to fix it.


A Quick Note on “No-Code” Tools

This is one of those moments that makes me smile (and occasionally sigh).

Tools love to market themselves as “no-code.” But the reality is:

Every serious website, in every framework, eventually needs customization.

Whether it’s:

  • Handling CMS navigation states
  • Adjusting dynamic filtering
  • Tweaking layout behavior
  • Improving UX edge cases

At some point, you write code.

And honestly? That’s not a flaw in the tool. It’s the nature of building custom digital experiences.

No-code platforms accelerate development.
They don’t eliminate the need for logic.

About the author

Kelly Barkhurst

Designer to Fullstack is my place to geek out and share tech solutions from my day-to-day as a graphic designer, programmer, and business owner (portfolio). I also write on Arts and Bricks, a parenting blog and decal shop that embraces my family’s love of Art and LEGO bricks!

By Kelly Barkhurst February 16, 2026

Recent Posts

Archives

Categories