Subscribe On YouTube

Join other subscribers and enjoy other Divi video tutorials!

How To Hide The Divi Theme Builder Header Until Scroll And Then Show As Sticky

Nelson Miller Profile Orange
In this tutorial I will show you how to hide the Divi Theme builder header until you start scrolling and then show it as sticky. 

▶️ Please watch the video above to get all the exciting details! 👆

Prerequisite: Theme Builder Header

This tutorial is for the Divi Theme Builder, and would not be relevant to the default Divi header. In order to follow this tutorial, you will need to have a Header template set up in Divi>Theme Builder. If you are new to the Theme Builder, I suggest taking our Divi Theme Builder mini-course to get familiar with it.

1. Add CSS Class To Header Section

Go to the Divi>Theme Builder and click the icon to edit the header template. Locate the blue section and open the settings. Go to the Advanced tab to the Custom CSS ID & Classes toggle and paste the CSS class “pa-header-hide-before-scroll” in the CSS Class input field.

add css class to make the Divi header hidden before scroll

2. Set The Header To Sticky

The point of this tutorial is to both hide the header at first, but then secondly to make the header stick to the top when you scroll down the page. To do that, you can use the built-in sticky settings in Divi. While in the section settings in the Advanced tab, scroll down to the Scroll Effects toggle and set the Sticky Position dropdown to “Stick to Top” and then click save.

set the Divi header to stick to top from the sticky settings

3. Add jQuery Snippet

There are two types of code, jQuery and CSS, which are needed to work together to achieve this affect. The jQuery code is essentially responsible for toggling the header’s visibility when the user scrolls down or up the page. Combined with the CSS in step #4 below, it creates a smooth transition effect for the header.

Where To Paste The jQuery Code

1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the jQuery tab in the custom code window in the Divi Visual Builder.

2. Child Theme
If you are using a child theme, paste this code into the scripts.js file (don't forget to remove the <script> tags at the beginning and end). If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.

3. Divi Theme Options Integration
Otherwise, paste this code in your Divi>Theme Options>Integrations tab in the "Add code to the < head > of your blog" code area.

If you need help understanding where to paste the code, please check out our complete guide about where to add custom code In Divi.

<script>
    jQuery(document).ready(function() {
        jQuery(window).scroll(function() {
            var scroll = jQuery(window).scrollTop();
            if (scroll >= 1) {
                jQuery(".pa-header-hide-before-scroll").addClass("pa-scroll-header");
            } else {
                jQuery(".pa-header-hide-before-scroll").removeClass("pa-scroll-header");
            }
        });
    });
</script>

4. Add CSS Snippet

As mentioned, this effect requires both jQuery and CSS to work together. This code will hide the header until the user scrolls down, then it will reveal it. If you scroll back up to the top, it will hide again.

Where To Paste The CSS Code

1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the CSS tab in the custom code window in the Divi Visual Builder.

2. Child Theme
If you are using a child theme, paste this code into the style.css file. If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.

3. Divi Theme Options Integration
Otherwise, paste this code in your Divi>Theme Options>Custom CSS code box.

If you need help understanding where to paste the code, please check out our complete guide about where to add custom code In Divi.

/*CSS to set the header hidden until scroll*/
header.et-l.et-l--header {
	height: 0;
}

.pa-header-hide-before-scroll {
	height: 0px;
	transform: translateX(0px) translateY(-300px);
	transition: transform 800ms ease 0ms, height 800ms ease 0ms;
	visibility: hidden;
}

.pa-scroll-header {
	height: auto !important;
	transform: translateX(0px) translateY(0px) !important;
	transition: transform 800ms ease 0ms, height 800ms ease 0ms;
	visibility: visible;
}

.pa-header-hide-before-scroll .et_pb_menu .et_pb_menu__wrap {
	display: none !important;
}

.pa-header-hide-before-scroll.pa-scroll-header .et_pb_menu .et_pb_menu__wrap {
	display: flex !important;
}

Code Explanation

The provided CSS code is designed to hide a header element until the user scrolls down the page. Here’s a breakdown of what each part of the code does:

1. The header.et-l.et-l–header selector sets the initial height of the header element to 0, effectively hiding it.

2. The .pa-header-hide-before-scroll class is used to hide the header before the user scrolls. It sets the height to 0px and translates it 300 pixels up (off the screen) with a CSS transform. It also adds a transition effect for the transform and height properties, making the header transition smoothly when it becomes visible.

3. The .pa-scroll-header class is applied to the header when the user scrolls down the page. It sets the height to “auto,” which means it will expand to its natural height. It also resets the transform property to its default values and applies the same transition effect as before.

4. The .pa-header-hide-before-scroll .et_pb_menu .et_pb_menu__wrap selector is used to hide a menu element within the header when it’s hidden before scrolling.

5. The .pa-header-hide-before-scroll.pa-scroll-header .et_pb_menu .et_pb_menu__wrap selector restores the visibility of the menu element when the header transitions to the “scroll” state.

The jQuery snippet above is used to trigger the class changes when the user scrolls.

Subscribe For More Things Like This!

At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

Blog Post Optin
Divi Logo (2)

Shop Our Divi Products

Plugins • Courses • Templates

Visit The Shop

Featured Products

Asset 4

New! Trail Guides

Follow a series of blog posts carefully arranged around a specific topic or goal! Keep track of your progress by marking posts completed, just like a free course!

View Trial Guides

Divi Tutorials On YouTube

Our videos have views! Join subscribers and enjoy over video tutorials!

Visit Our Channel

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

21 Comments

Comments By Members

These comments are highlighted because they were posted by fans who have a membership on this site.

  1. Kelly Lerbekmo <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

    Loved the tutorial, thank you! Wondering… rather than hiding the whole header before scrolling, can you suggest how I’d hide just the logo of the header? Then, when someone scrolls, the whole header including the logo becomes visible?

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi Kelly!

      Please use the following CSS code for it:

      .pa-scroll-header .et_pb_menu__logo img{
      display: block !important;
      }

      .pa-header-hide-before-scroll .et_pb_menu__logo img {
      display: none;
      }

      Hope it helps!

      Reply

Comments By Others

  1. Juri

    Hey, nice Tutorial!
    Is there a way to prevent the header from disappearing when the Page is scrolled to the top again?

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi Juri!

      Please use the following script in that case:

      jQuery(document).ready(function () {
      jQuery(window).scroll(function () {
      var scroll = jQuery(window).scrollTop();
      if (scroll >= 1 && !jQuery(“.pa-header-hide-before-scroll”).hasClass(“pa-scroll-header”)) {
      jQuery(“.pa-header-hide-before-scroll”).addClass(“pa-scroll-header”);
      }
      });
      });

      Hope it helps!

      Reply
  2. Pamela

    Gave up on the ET version, followed the steps while listening to your video, and it works!!
    Maybe a bit too good, since now I can´t see my heading section in the theme builder anymore.

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi Pamela!

      Can you please share some more details? Did you add the heading section in the global header in theme builder?

      Reply
      • Amy

        Hello, awesome tutorial, but I’m encountering the same issue here.
        I did add the heading section in the global header in the theme builder.
        Plus, an undesired margin appears on the front end, the header is shifted approx. 30px away from the top of the screen… Need help please !

  3. Carol Snyder

    Hi Nelson,

    Thanks for the Great help and information. I’m currently using the sticky header code. However, when using an anchor link, it appears to scroll past the desired spot. I tried to use the scroll-margin-top, but Divi doesn’t like it. Do you have a fix so that I can use your code as well as have using an anchor function?

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi Carol!

      The anchor issue is a bug at the Divi end. You can get the fix from Elegant Themes support.

      Reply
  4. Jim Sparks

    Hi there! I love this. Is there any way to make the header appear after the user has scrolled maybe a certain percentage of the screen? Like if the hero section is full viewport height, have the header appear as the second section gets to the top of the viewport.

    Does that make sense?

    Reply
  5. John

    Hi Nelson
    Slightly off topic but I have the opposite issue. The header for my site is hiding on load, I don’t want it to any more and I can not work out what’s causing it to happen. It’s ignoring the Divi settings and I can’t find any code to make it do it. Any ideas?

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi John!

      Please remove the above codes (if added), if it doesn’t resolve the issue, share the URL of the page to check further.

      Reply
  6. Tom Parkinson

    Thanks for this. Really useful. Is there a way to get the header to appear at the top after the user has scrolled past a particular section, please? Basically, I have my top section, and when a user scrolls past this, I would like the header to load after the top head is out of view. Is that possible, please?

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi Tom!

      Yes, in the above code, you can see the top variable is assigned to a value greater than 1.

      if (scroll >= 1)

      You can increase the value to equal the height of the first section. Hope it helps!

      Reply
      • Tom Parkinson

        That’s brilliant! Thanks so much.

  7. Michel

    Thank you so much for this tutorial! I struggled with the ET:s version of the tutorial but this one did the trick. I´m surprised that Divi does not have a toggle for “Hide menu until scroll”. Keep those tutorials coming, they are very, very helpful!

    Reply
  8. Stephane JACQUES

    Wouaww ! Very cool !
    Thank you so much Nelson, it’s very efficient as usual.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

Shopping cart0
There are no products in the cart!
You may be interested in…
$19.00$22.50

Select options This product has multiple variants. The options may be chosen on the product page

$16.50$24.00

Select options This product has multiple variants. The options may be chosen on the product page

$16.50$24.00

Select options This product has multiple variants. The options may be chosen on the product page

$19.00$24.00

Select options This product has multiple variants. The options may be chosen on the product page

$20.50$24.00

Select options This product has multiple variants. The options may be chosen on the product page

Graphic showcasing Divi Assistant features and toolset.
From: $69.00 / year

Select options This product has multiple variants. The options may be chosen on the product page

Divi Search Helper Plugin By Pee Aye Creative
From: $29.00 / year

Select options This product has multiple variants. The options may be chosen on the product page

Continue shopping
0