Skip to content

[offcanvas] - triggers unexpected scroll to top when scroll-padding-top is set on html, body #41615

@webexpr-dhenriet

Description

@webexpr-dhenriet

Prerequisites

Describe the issue

When using an offcanvas component, closing it (either via the close button or by clicking on the backdrop) unexpectedly scrolls the page to the top — but only when the following CSS rule is applied:

html, body {
  scroll-padding-top: 100px;
}

This seems to be a Chromium-specific issue.

To Reproduce
Steps to reproduce the behavior:

  1. Add scroll-padding-top: 100px; to html, body
  2. Add an offcanvas with a toggle and a close button
  3. Scroll the page down
  4. Open the offcanvas
  5. Click on the close button or the backdrop to dismiss it
  6. Observe the page jumps back to the top

Expected behavior
The page scroll position should not change when closing an offcanvas, regardless of scroll-padding-top.

Environment

  • Bootstrap version: 5.3.7, 5.3.2
  • Browser:
    • Firefox: Works correctly, no scroll jump
    • Chrome (v125+) and Edge (v125+): Scrolls to top when closing offcanvas
  • OS: Windows

Removing scroll-padding-top fixes the issue: the scroll position remains unchanged after closing the offcanvas.

Reduced test cases

Codepen => https://codepen.io/David-Henriet/pen/GgpqLrm

bt-offcanvas-ezgif.com-gif-maker.webm

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Chrome

What version of Bootstrap are you using?

5.3.7, 5.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions