---
title: "Loading Overlay · Base UI — StyleX Blocks"
description: "Busy states that fill a container, cover it, or take over the screen while content loads."
url: "https://stylexblocks.com/components/base-ui/loading-overlay/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Loading Overlay

Busy states that fill a container, cover it, or take over the screen while content loads.

- Behavior engine: Base UI
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/loading-overlay.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/loading-overlay.md)
- Category: Feedback
- Variants: overlay, fill, fullscreen
- HTML page: https://stylexblocks.com/components/base-ui/loading-overlay/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style base-ui
```

Then add the item as source you own:

```sh
npx stylexblocks add loading-overlay
```

Equivalent: `npx shadcn add @stylexblocks/loading-overlay`. Registry item JSON: https://stylexblocks.com/r/base-ui/loading-overlay.json

## Usage

```tsx
import { LoadingOverlay } from "#components/ui/base-ui/loading-overlay.tsx";
import { Spinner } from "#components/ui/base-ui/spinner.tsx";

export function Example() {
  return (
    // variant="overlay" covers the nearest positioned ancestor;
    // "fill" fills a flex parent; "fullscreen" fixes over the viewport.
    // Parts compose via render.
    <LoadingOverlay.Root variant="overlay" role="status">
      <Spinner size="lg" />
      <LoadingOverlay.Text>Loading projects…</LoadingOverlay.Text>
    </LoadingOverlay.Root>
  );
}
```

## Source

`components/ui/base-ui/loading-overlay.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createSlotRecipeContext } from "#lib/base-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe } from "#lib/recipe-props.ts";
import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";
import { colors } from '@stylexblocks/ui/tokens/colors.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'

const loadingOverlayRoot = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    alignItems: 'center',
    justifyContent: 'center',
    padding: spacing._4,
    transitionProperty: 'opacity',
    transitionDuration: durations.slower,
  },
})

const loadingOverlayRootVariants = stylex.create({
  fill: {
    flex: 1,
    height: '100%',
    // Chakra's virtual `currentBg` token has no StyleX equivalent; the page
    // background is the closest semantic token.
    backgroundColor: semanticColors.bg,
  },
  fullscreen: {
    position: 'fixed',
    inset: 0,
    zIndex: zIndices.modal,
    backgroundColor: semanticColors.bg,
  },
  overlay: {
    position: 'absolute',
    inset: 0,
    // `currentBg/50` — a half-transparent wash of the page background
    backgroundColor: `color-mix(in oklch, ${semanticColors.bg} 50%, ${colors.transparent})`,
  },
})

export type LoadingOverlayVariant = keyof typeof loadingOverlayRootVariants

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const loadingOverlayRecipe = defineSlotRecipe({
  slots: {
    root: { styles: loadingOverlayRoot, variants: loadingOverlayRootVariants },
  },
  defaultVariants: { variant: "fill" },
});

// The recipe has a single `root` slot; the label part is local chrome so
// busy text sits consistently under the spinner.
const chrome = stylex.create({
  text: {
    marginTop: spacing._2_5,
    fontSize: fontSizes.sm,
    color: semanticColors.fgMuted,
  },
});

/**
 * Loading Overlay — a presentational busy state composed from the
 * loading-overlay slot recipe: `variant="fill"` fills its flex parent,
 * `variant="overlay"` covers the nearest positioned ancestor, and
 * `variant="fullscreen"` fixes itself over the viewport (above sticky page
 * chrome via the modal z-index). Pair it with a spinner and a short label;
 * every part composes via `render` through Base UI's `useRender` primitives.
 * Add `role="status"` so the busy state is announced.
 */
const { withProvider, withContext } = createSlotRecipeContext(loadingOverlayRecipe);

export const LoadingOverlay = {
  Root: withProvider("div", "root", "LoadingOverlayRoot"),
  Text: withContext("span", () => [chrome.text], "LoadingOverlayText"),
};
```
