Updated for Divi 5: I tested both versions of this effect on Divi 5.18 and they work: Divi 5 still renders sections as div.et_pb_section with the ID you give them, the Menu module keeps the Divi 4 menu markup, and jQuery is still loaded. The steps now show where to add the CSS class and the code in Divi 5 (with the Divi 4 path in brackets), and the Extended Version has its complete JavaScript code.
Ready to take your website's navigation to the next level? This is an in-depth walkthrough tutorial on creating a sleek One-Page Menu Navigation with Active Anchor Links in Divi. This advanced tutorial uses jQuery and CSS, but don't worry, I'll explain everything step by step.
In the video, you'll learn how to set up a smooth scrolling navigation menu that highlights active sections as you scroll. And in this blog post, I've included code snippets that you can easily copy and paste to get this effect on your own site.
This tutorial was streamed live inside the Divi Stylist Community, an online space for Divi Stylist Academy students.
The video was recorded in Divi 4. The code works the same way in Divi 5; what changed is where you add the CSS class and the section IDs (Advanced → Attributes in Divi 5), and the Extended Version below uses slightly updated code.
Excited to see this in action? Check out my Divi child theme, Identity. It features a one-page design using this exact navigation setup. See the demo and experience the seamless scrolling for yourself!

And if you're ready to start learning, let's go!
How do active anchor links work in a Divi one-page menu?
A short jQuery script watches the scroll position, and when the top of a section passes the middle of the screen, it adds an active CSS class to the menu link whose URL ends with # plus that section's ID. You then style that class with CSS, so the highlighted link always matches the section your visitor is reading.
Divi doesn't do this on its own. The Menu module's Active Link Color is meant for the page currently being visited, not for the section in view, and Divi's built-in smooth scrolling only takes care of the jump when someone clicks an anchor link.
What you need before you start
You need a page where every section has a CSS ID, and a menu whose links point to those IDs.
- Section IDs: open each section's settings and give it a unique ID, for example
about. In Divi 5: Advanced → Attributes → Add Attribute → ID (in Divi 4: Advanced → CSS ID & Classes → CSS ID). - Anchor links: in Appearance → Menus, add Custom Links with URLs like
#aboutor/your-page/#about. The script only checks that the link URL ends with#about, so both work.
Where to add the code in Divi 5
Add the JavaScript site-wide in Divi → Theme Options → Integration, or on a single page with a Code module, and wrap it in <script> tags in both places. In a child theme JavaScript file, use it without the tags.
- JavaScript, whole site: Divi → Theme Options → Integration → "Add code to the < head > of your blog" (same in Divi 4).
- JavaScript, one page: a Code module anywhere on the page.
- CSS, whole site: Divi → Theme Options → General → Custom CSS, or your child theme's style.css.
- CSS, one page: in Divi 5, the gear icon top-left → Page Settings → Advanced → Custom CSS (in Divi 4: Page Settings → Advanced → Custom CSS).
Simple version: highlight the active link with a CSS class
The simple version adds an active class to the link itself, so you can change its color or show an underline. It works with a Menu module or a Text module full of links.
Step 1: Add the CSS class
Add a CSS class of dl-anchor-menu to a Menu or a Text module. In Divi 5: Advanced → Attributes → Add Attribute → CSS Class (in Divi 4: Advanced → CSS ID & Classes).
Step 2: Add the JavaScript code
Add the following JavaScript code to your child theme. If you'd rather use the Theme Options Integration tab or a Code module, wrap the code inside <script> tags:
jQuery(document).ready(function($) {
// Cache the link elements
var navLinks = $('.dl-anchor-menu a');
// Add a scroll event listener to the window
$(window).scroll(function() {
// Get the current scroll position
var scrollPosition = $(this).scrollTop();
var windowHeight = $(window).height();
// Calculate the center of the screen
var screenCenter = scrollPosition + windowHeight / 2;
// Loop through each visible section (hidden sections report a position of 0)
$('div.et_pb_section:visible').each(function() {
// Get the position of the current section
var sectionTop = $(this).offset().top;
var sectionId = $(this).attr('id');
// Check if the section crosses the center of the screen
if (sectionTop <= screenCenter) {
// Remove the "active" class from all links
navLinks.removeClass('active');
// Add the "active" class to the link corresponding to the current section
$('.dl-anchor-menu a[href$="#' + sectionId + '"]').addClass('active');
}
});
});
// Highlight the right link on page load too
$(window).trigger('scroll');
});
This code applies an active CSS class to each link within the module that has the dl-anchor-menu CSS class, but only if the link's URL contains the ID of the section currently visible in the viewport.
Two small updates compared to the original code: sections hidden on the current device are skipped (a hidden section reports a position of 0, so it would always "win"), and the script runs once on page load, so the right link is highlighted before your visitor scrolls.
Step 3: Style the active link
Use the active CSS class to style the highlighted menu item. In the example below, we created a pseudo-element:
.dl-anchor-menu a::before {
content:'';
width:100%;
height:3px;
background: #000;
display: block;
position: absolute;
bottom: -20px;
opacity: 0;
transition: all .3s;
}
.dl-anchor-menu a {
position:relative;
}
.dl-anchor-menu a.active::before {
bottom: 0;
opacity: 1;
}
.dl-anchor-menu.et_pb_menu a.active {
color: lightsalmon!important;
}
Extended version: an animated highlight that slides between links
The extended version adds the active class to the menu item (the LI) and moves one rounded background shape behind it, so the highlight slides from link to link as you scroll. It needs a Menu module.
Step 1: Add the CSS class to a Menu module
Add a CSS class of dl-anchor-menu to a Menu module. In Divi 5: Advanced → Attributes → Add Attribute → CSS Class (in Divi 4: Advanced → CSS ID & Classes).
Step 2: Add the JavaScript code
Add the following JavaScript code to your child theme. If you prefer to use the Theme Options Integration tab or a Code module, make sure to wrap the code inside <script> tags:
jQuery(document).ready(function($) {
// Add the animated highlight element to the menu
var menuList = $('.dl-anchor-menu nav > ul');
menuList.append('<div id="dl-anchor-active"></div>');
var highlight = $('#dl-anchor-active');
// Cache the top-level list items
var navItems = menuList.children('li');
// Add a scroll event listener to the window
$(window).scroll(function() {
// Get the current scroll position
var scrollPosition = $(this).scrollTop();
var windowHeight = $(window).height();
// Calculate the center of the screen
var screenCenter = scrollPosition + windowHeight / 2;
// Loop through each visible section (hidden sections report a position of 0)
$('div.et_pb_section:visible').each(function() {
// Get the position of the current section
var sectionTop = $(this).offset().top;
var sectionId = $(this).attr('id');
// Check if the section crosses the center of the screen
if (sectionTop <= screenCenter) {
// Remove the "active" class from all list items and hide the highlight
navItems.removeClass('active');
highlight.css({ opacity: 0 });
// Add the "active" class to the LI of the link that points to the current section
var currentItem = navItems.children('a[href$="#' + sectionId + '"]').parent('li');
currentItem.addClass('active');
// Move the highlight behind the active list item
if (currentItem.length) {
highlight.css({
left: Math.round(currentItem.offset().left - menuList.offset().left),
width: currentItem.outerWidth(),
opacity: 1
});
}
}
});
});
// Highlight the right link on page load too
$(window).trigger('scroll');
});
The JavaScript code above adds an active CSS class to the parent LI element of each link within the module that has the dl-anchor-menu CSS class, but only if the link's URL contains the ID of the section currently in the viewport. Additionally, it creates a new element with the ID dl-anchor-active, which will be positioned behind the active list item using CSS.
Step 3: Style the animated highlight
Add the following CSS code to style the animated highlight element, adjust the margin and height to match the size of your navigation.
.dl-anchor-menu .et-menu {
position: relative;
}
.dl-anchor-menu .et-menu > li {
z-index: 3;
}
#dl-anchor-active {
position: absolute;
transition: all .3s linear;
top: 50%;
margin-top: -20px;
height: 40px;
z-index: 2;
background: #eee;
border-radius: 30px;
opacity: 0;
}
The highlight takes the full width of the menu item, including Divi's default 11px padding on each side, so you don't need a negative margin to center it. margin-top should always be minus half of the height.
Why are all my menu links highlighted at once?
WordPress gives every menu link that points to the current page the current-menu-item class, and anchor links count, so the Menu module's Active Link Color colors all of them. Set Active Link Color (Design → Menu Text) to the same color as your normal links and style only the active class from this tutorial.
A few other things to check if the highlight doesn't behave:
- Nothing gets highlighted: check that the section ID and the end of the link URL match exactly (IDs are case-sensitive) and that the module has the dl-anchor-menu class.
- The highlight disappears between sections: a section without an ID removes the highlight while it's in the middle of the screen. Give it an ID, or leave it like that on purpose for sections that aren't in the menu.
- The last link never gets highlighted: a section becomes active when its top reaches the middle of the screen. If your last section (plus the footer) is shorter than half the screen, the page can't scroll far enough. Add some bottom padding or make the section taller.
And that's it!
I hope you enjoyed this tutorial and found it helpful! If you have any questions, share them in my Divi Lovers Facebook group, and I'll do my best to help you out.
If you have trouble with this tutorial or any other part of designing a website, I offer 1-on-1 web design assistance: check the options here!
And if you'd like to build a one-page website with this type of navigation fast, Identity is a great way to kickstart your project and save hours upon hours while gaining pixel-perfect, easily customizable design.





