Resource
/
Remove Unwanted Horizontal Scrollbar

Details

Category
Utilities & Scripts
Last Updated
Feb 2, 2026

Overview

Use this code when your page shows a horizontal scrollbar even though the layout looks normal.

This usually happens when an element stretches a few pixels beyond the screen because of margins, positioning, fixed widths, or animations.

The snippet hides that overflow and keeps the layout locked to the viewport.

It works well, but it’s still a patch.

You should track down the element causing the issue and fix it properly.

Setup

00

Add External Scripts

Copy & paste the scripts before the </body> tag of your project. If you added them before for another setup, skip this step.

00

Add HTML

Place the code in an HTML widget or add it through Elementor → Custom Code (before the closing </body> tag) either globally or only on selected pages.

00

Add custom CSS

Paste the code through the page or site settings, or add it via Elementor → Custom Code (before </body>) for broader use.

html, body {
  overflow-x: hidden;
}
00

Add custom Javascript

Paste the script through Elementor → Custom Code (set to load after </body>) for site-wide or page-specific loading.

00

Add custom PHP

Place the PHP snippet inside your theme’s functions.php or using any code snippet to enable logic.

00

Publish and preview live

Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.