Skip to content

Reserve space for scrollbars in sidebar to avoid layout shift#3797

Open
delucis wants to merge 2 commits intomainfrom
chris/sidebar-scrollbar
Open

Reserve space for scrollbars in sidebar to avoid layout shift#3797
delucis wants to merge 2 commits intomainfrom
chris/sidebar-scrollbar

Conversation

@delucis
Copy link
Copy Markdown
Member

@delucis delucis commented Mar 31, 2026

Description

User agents vary in how they render scrollbars. Some, like macOS with a trackpad, are designed to appear and disappear and overlay on top of the UI. For these devices, this PR doesn’t change anything:

Before After
sidebar with even padding either side of its contents an identical image to before

However, in other circumstances, scrollbars require a gutter which is deducted from an element’s width (with padding etc. applied from the gutter’s edge). In these cases, the change in this PR reserves that gutter space even for sidebars that do not overflow the viewport:

Before After
sidebar with even padding, as shown above sidebar with more padding on the right than on the left to save space for the scrollbar

Note the additional whitespace between the group carets and the sidebar border in the “after” screenshot.

This isn’t an amazing change to have to make: for sites whose scrollbar never overflows, user agents that need it will still reserve that extra space, unbalancing the layout pointlessly. Having the even padding on both sides of the scrollbar would be visually more pleasing, I think.

There is also the scrollbar-gutter: stable both-edges variant, which while balancing spacing either side of the scrollbar content, would introduce a lot of extra whitespace on the outer edge. You would think you might be able to adjust for that with padding but a) we don’t know when a gutter is reserved and when not and b) we don’t know the gutter width to know how much to reduce padding by.

So it’s a choice between prettier layout and avoiding layout shift when users interact. On balance, it’s probably worth avoiding layout shift and there are design solutions we could explore to lessen the visual impact (such as removing the border for example).

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

🦋 Changeset detected

Latest commit: 9e6b674

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit 9e6b674
🔍 Latest deploy log https://app.netlify.com/projects/astro-starlight/deploys/69cbfbb024657200086b0c5e
😎 Deploy Preview https://deploy-preview-3797--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Mar 31, 2026
@astrobot-houston
Copy link
Copy Markdown
Contributor

astrobot-houston commented Mar 31, 2026

size-limit report 📦

Path Size
/index.html 5.61 KB (+0.02% 🔺)
/_astro/*.js 26.03 KB (0%)
/_astro/*.css 16.05 KB (+0.07% 🔺)

@delucis delucis added the 🌟 minor Change that triggers a minor release label Mar 31, 2026
@delucis delucis added this to the v0.39 milestone Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 core Changes to Starlight’s main package 🌟 minor Change that triggers a minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

content layout shift in sidebar due to scrollbar

4 participants