@zag-js/remove-scroll
JavaScript utility to remove scroll on body
This package has a good security score with no known vulnerabilities.
Community Reviews
Solid scroll-locking utility with excellent type safety and framework integration
The TypeScript definitions are excellent with clear function signatures and options. The library properly manages multiple simultaneous scroll locks (counting references internally), so you don't have to worry about unlocking too early when multiple modals stack. It also preserves scrollbar width compensation by adding padding, preventing the jarring content shift most naive implementations cause.
Documentation is minimal but the API surface is small enough that it's not a major issue. The main gotcha is remembering to call the cleanup function - if you forget, scroll stays locked. Would benefit from more examples showing integration patterns with different frameworks, though the existing Zag.js component examples provide some guidance.
Best for: Projects needing robust scroll-locking for modals, drawers, or overlays with proper edge case handling.
Avoid if: You need a batteries-included solution with framework-specific hooks already built in.
Lightweight, reliable scroll-locking utility with minimal dependencies
From a security perspective, this package has practically zero attack surface. It's a pure DOM manipulation utility with no network calls, no external dependencies beyond peer dependencies, and no data processing. The code is transparent and auditable. Input validation isn't really applicable here since it accepts minimal configuration, mostly just DOM references.
The main consideration is that it's part of the larger Zag.js state machine library ecosystem, so you're pulling in patterns from that project. The package itself is well-maintained with regular updates, and error handling is straightforward—it fails gracefully if DOM elements aren't available rather than throwing unclear exceptions.
Best for: Projects needing reliable scroll-locking for modals, drawers, or overlays where you want a tested solution without reinventing the wheel.
Avoid if: You need highly customized scroll behavior or are already using a full-featured modal library that includes scroll management.
Robust scroll lock utility with minimal API surface and smart defaults
The library shines in modal/dialog scenarios where you need scroll locking without layout shift. It preserves the scrollbar gap by default, preventing the jarring content reflow that happens when scrollbars disappear. The code is small (~2KB) and integrates cleanly with any framework since it's vanilla JS. Error messages are minimal because there's not much that can go wrong, but the TypeScript types are helpful.
The main downside is sparse standalone documentation—you'll need to reference the broader Zag.js docs or read the source. It's also part of a larger ecosystem, so if you just need scroll locking without other Zag utilities, you might prefer a more focused package. That said, it works reliably and I haven't encountered bugs in production use.
Best for: Developers building modals, drawers, or overlays who need reliable scroll locking without reinventing the wheel.
Avoid if: You need complex scroll management with allowlists for specific scrollable regions or are already using a full UI component library with built-in scroll locks.
Sign in to write a review
Sign In