Adding a Preloader to Your Divi Site

Intermediate

CSS, Javascript

Details

Preloaders are a fantastic addition to any Divi WordPress website. As the first element your users encounter upon entering your site, preloaders remain visible until the entire page is fully loaded. This not only prevents users from experiencing delays while waiting for website resources to load but also provides a seamless, professional feel to your site. Follow this guide to easily add a preloader to your website using CSS.

Snippets Demo

Code

1

Description:
Add the following CSS to the Theme Options > General > Custom CSS section. Be sure to update the background image URL to a GIF that you have uploaded to your Media Library. Additionally, adjust the width and height CSS properties to accommodate the size of your GIF.

Language: CSS

Where to add: Divi Theme Options

                        /* PRELOADER */
.preloader {
   position: fixed; /* Fixes the preloader to the viewport */
   top: 0; /* Aligns the preloader to the top of the viewport */
   left: 0; /* Aligns the preloader to the left of the viewport */
   right: 0; /* Extends the preloader to the right edge of the viewport */
   bottom: 0; /* Extends the preloader to the bottom edge of the viewport */
   background-color: #fefefe; /* Sets the background color of the preloader */
   z-index: 100000; /* Ensures the preloader is on top of all other elements */
   height: 100%; /* Sets the height to cover the entire viewport */
   width: 100%; /* Sets the width to cover the entire viewport */
   overflow: hidden !important; /* Prevents any overflow content */
}
.preloader .status {
   width: 50px; /* Sets the width of the loading GIF */
   height: 50px; /* Sets the height of the loading GIF */
   position: absolute; /* Positions the GIF absolutely within the preloader */
   left: 50%; /* Centers the GIF horizontally */
   top: 50%; /* Centers the GIF vertically */
   background-image: url(/wp-content/.../loading.gif); /* Sets the loading GIF image */
   background-repeat: no-repeat; /* Prevents the background image from repeating */
   background-position: center; /* Centers the background image */
   -webkit-background-size: cover; /* Ensures the background image covers the container (for WebKit browsers) */
   background-size: cover; /* Ensures the background image covers the container */
   margin: -50px 0 0 -50px; /* Offsets the GIF to perfectly center it */
   opacity: .5; /* Sets the opacity of the GIF */
}
                    
2

Description:
Add the following JavaScript to the section of your website. You can do this in the Theme Options area of Divi by navigating to the "Integrations" tab. IMPORTANT: Please add SCRIPT tags on either side of the JavaScript.

Language: Javascript

Where to add: Divi Theme Options

                         // Ensures the whole site is loaded before running the script
    jQuery(window).load(function () {
        "use strict"; // Enforces strict mode to catch common coding errors
        // Checks if the Divi Builder (backend and frontend) is not active
        if (jQuery('.et-bfb').length <= 0 && jQuery('.et-fb').length <= 0) { 
            // Fades out the loading animation
            jQuery(".status").fadeOut();
            // Delays for 1 second, then fades out the whole preloader DIV
            jQuery(".preloader").delay(1000).fadeOut("slow");
        } else {
            // If Divi Builder is active, hides the preloader immediately
            jQuery(".preloader").css('display', 'none');
        }
    }); 

<!-- Preloader DIV that covers the entire website -->
<div class="preloader">
    <!-- Status DIV for the loading animation -->
    <div class="status"></div>
</div> 
                    

Related Snippets

Explore more from Divi Engine

Divi Form Builder

Divi Form Builder

From simple contact forms to complex frontend post or product creation, Divi Form Builder has you covered.

Divi Form Builder
Find out more
Divi Machine

Divi Machine

Build complex websites that displays dynamic fields you can filter, search and so much more with the Divi Builder.      

Divi Machine
Find out more
Divi BodyCommerce

Divi BodyCommerce

A versatile toolkit for developers using Divi and WooCommerce together, designed to boost your e-commerce site and achieve greater conversion rates.    

Divi BodyCommerce
Find out more
Divi Handoff

Divi Handoff

Let clients update content without touching the Divi Builder. Design layouts once, connect them to Flexible Content fields, and give editors simple forms for text, images, and sections.

Divi Handoff
Find out more
Divi Loop Extender

Divi Loop Extender

Unlock the Full Power of Divi 5 Loop Builder Add advanced sorting, filtering, and relationship logic right inside the Visual Builder.

Divi Loop Extender
Find out more
Divi Membership

Divi Membership

Monetize your Divi websites by transforming them into membership sites with seamless subscription management, user-friendly interfaces, and customizable membership tiers.

Divi Membership
Find out more
Divi Machine Accounts

Divi Machine Accounts

Build an account area for your customers to edit their details, access wishlist, submitted posts and more. *Note: Requires Divi Machine installed and active

Divi Machine Accounts
Find out more
Divi Ajax Filter

Divi Ajax Filter

Filter WooCommerce, Posts & Custom Posts without reloading the page.    

Divi Ajax Filter
Find out more
Divi Mobile

Divi Mobile

Divi Mobile helps you create beautiful looking mobile menus without having to code.

Divi Mobile
Find out more
Divi Nitro

Divi Nitro

Give your Divi website that extra boost of speed with our Divi Nitro plugin to enhance your customer's experience.

Divi Nitro
Find out more
Divi Protect

Divi Protect

Password protect the content of your Divi website with our Divi Protect plugin. Keep unwanted eyes out!

Divi Protect
Find out more
Divi Mega Menu

Divi Mega Menu

Create stunning, responsive, and content-rich mega menus using the Divi Builder you already know. No coding required.  

Divi Mega Menu
Find out more