Magento 2 Disable browser scrolling while Minicart (DropdownDialog) is open?

Magento 2 Disable browser scrolling while Minicart (DropdownDialog) is open?

September 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 Disable browser scrolling while Minicart (DropdownDialog) is open?

Disable Browser Scrolling for Magento 2 Minicart (DropdownDialog)

In Magento 2, you can indeed disable browser scrolling while the minicart is open to improve user experience. This involves modifying the CSS of the minicart to add a fixed position and overflow property.

Here’s how you can achieve this:

Understanding the Issue

The default behavior in Magento 2 allows users to scroll the page even when the minicart is open, which can be confusing for some users as it obscures the content behind the minicart. Disabling scrolling prevents this issue by fixing the minicart overlaying the main content.

Solution: Modifying CSS

To disable scrolling, you need to target the dropdownDialog container and apply specific CSS properties. You can do this by overriding the default styles or adding custom styles using Magento’s theme inheritance system.

Method 1: Using Magento Theme Inheritance

Create a new CSS file in your theme directory (e.g., app/design/frontend/Vendor/Theme/Magento_Theme/web/css/source/_extend.css).

Add the following CSS rules to target the minicart:

#minicart-content-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.minicart.empty {
    overflow-y: auto;
}

This code will set the minicart container to a fixed position, covering the entire page. The overflow property will allow scrolling within the minicart content.

Method 2: Using JavaScript/jQuery

If you prefer a more dynamic approach, you can use JavaScript or jQuery to apply and remove CSS classes on click events of the dropdownDialog trigger target (the “Show Cart” link).

Create a new script file in your theme directory (e.g., app/design/frontend/Vendor/Theme/Magento_Theme/web/js/minicart.js).

Add the following code:

require(['jquery'], function ($) {
    $(document).on('click', '[data-role=dropdownDialog]', function() {
        if (!$(this).hasClass('scroll-disabled')) {
            $('html').addClass('scroll-disabled');
        }
    });

    $(document).on('hidden.bs.dropdown', '[data-role=dropdownDialog]', function () {
        if ($(this).hasClass('scroll-disabled')) {
            $('html').removeClass('scroll-disabled');
        }
    });
});

In your theme’s requirejs-config.js file, ensure you have the following configuration to load the custom script:

var config = {
    map: {
        '*': {
            'jquery/jquery-creditcardvalidator': 'Vendor_Theme/js/minicart',
        },
    }
};

This JavaScript code listens for click events on the minicart trigger and adds a scroll-disabled class to the <html> element when the minicart opens. The hidden.bs.dropdown event removes this class when the minicart is closed, restoring normal scrolling.

Conclusion

Disabling browser scrolling while the Magento 2 minicart is open can significantly improve usability and prevent user confusion. By following either of the methods described above—modifying CSS or using JavaScript—you can achieve this without any significant changes to your theme’s core files.

Remember that these solutions require knowledge of custom theme development in Magento 2, which may not be suitable for beginners. If you’re unsure about implementing these changes, consider consulting a professional developer.

For more advanced techniques and best practices in Magento 2 theme development, I recommend visiting Laravel Company’s blog. They provide excellent resources and tutorials on Magento customization and optimization.

Magento 2 Checkout Database Themes

Our network