Skullet
Skullet provides smart, auto-measured skeleton loading states that eliminate layout shift by tracing your actual component dimensions before content arrives.
Skullet is a sophisticated library designed to manage loading states by creating intelligent skeleton screens that mirror the exact layout of the content about to be loaded. Developed by Lochie Axon, Skullet eliminates the common issue of layout shift by measuring the actual content before it appears. Instead of relying on manually designed placeholders, Skullet renders the content invisibly, traces its geometry—including line breaks, text blocks, and media dimensions—and generates a perfectly synchronized skeleton. This ensures that when the real data arrives, the transition is seamless and prevents the page from jumping or resizing.
The library functions by leveraging the browser's layout engine to determine the precise size of components. By measuring DOM elements with techniques like Range.getClientRects() and calculating font metrics, it generates an accurate representation of the pending UI. These skeletons are then displayed to the user with consistent shimmer animations, colors, and motion settings, which are managed globally to ensure visual uniformity across the entire application, even as different parts of the page finish loading at different times.
Some of the key features are:
- Content-Aware Measurement: Automatically traces real content geometry to generate skeletons that match final layout dimensions.
- Framework Support: Native integration for React, Vue, Svelte, and vanilla JavaScript environments.
- Layout Stability: Completely eliminates layout shifts by accurately mapping the skeleton to the eventual content size.
- Customizable Reveals: Offers multiple transition modes including smart, sequence, together, and sweep to control how skeletons are replaced by content.
- Persistent Shapes: Remembers skeleton shapes in localStorage, allowing for instant skeleton rendering on subsequent visits.
- Theming Engine: Comprehensive CSS variable support for defining colors, animation speeds, border radii, and text rendering metrics.
- Accessibility Compliance: Properly handles aria-busy states, hides skeletons from screen readers, and respects system-wide reduced motion preferences.
- SSR Ready: Provides seamless support for Server Side Rendering (SSR) and React Server Components to ensure zero-flicker loading experiences.
To implement Skullet, developers wrap their content components within a skeleton provider or component. By providing a sample data object, the library can measure the intended output while the actual data is being fetched. For complex UI elements that cannot be easily measured, such as specific icons or charts, developers can define custom skeleton components using the provided SkeletonBox utility. The configuration can be fine-tuned via the SkulletProvider, which enables global settings for themes, reveal behaviors, and even debugging overlays that highlight measurement accuracy.
Some common use cases include:
- Dashboard Loading: Creating smooth loading states for data-heavy business dashboards where multiple panels update asynchronously.
- Content Feed Transitions: Ensuring that article feeds or social media streams maintain their scroll position and layout integrity while new entries load.
- E-commerce Product Grids: Preventing product cards from jumping as product images and descriptions finish rendering.
- Streaming Content: Handling streamed server responses in modern frameworks like Next.js or SvelteKit to provide immediate visual feedback while data arrives.
- Performance Optimization: Reducing perceived latency in single-page applications by providing immediate visual placeholders that match the final page structure.