# Setup

Install Mosaic, import its stylesheet, set a color scheme, and give your app root its own stacking context.

Mosaic is in active development. Its components and primitives can have breaking changes in minor releases, so pin an exact version.

## Install

```sh
pnpm add --save-exact @clerk/mosaic
```

## Import the stylesheet

Mosaic components carry no runtime style injection. The stylesheet holds every component rule, so nothing renders correctly without it. At your app’s CSS entry point, import it once:

```css
@import '@clerk/mosaic/styles.css';
```

## Set a color scheme

Mosaic’s colors use [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark), which resolves against the `color-scheme` in scope. Mosaic does not set one, so your app must:

```css
:root {
  color-scheme: light dark;
}
```

Use `light dark` to follow the visitor’s system setting, or `light` or `dark` to pin one. You can also set it on any element to scope a scheme to part of the page.

Without a `color-scheme`, components can render with transparent backgrounds or missing colors. This is most visible when your build runs the stylesheet through Lightning CSS, as Tailwind CSS v4 does. For browser targets without native `light-dark()` support, Lightning CSS rewrites `light-dark()` into a fallback that only works once a `color-scheme` is declared, so each color resolves to two values at once (for example `#171717 #fafafa`), which is invalid and drops the property.

## Isolate your app root

Popups, like `Menu` and `Popover`, portal to `document.body` and set no `z-index` of their own. A page element with a high `z-index`, like a sticky header, can paint over them.

Give the element that wraps your page content its own stacking context:

```tsx
<body>
  <div style={{ isolation: 'isolate' }}>{children}</div>
</body>
```

Every `z-index` inside it then stays below the popups. Don’t put it on `<body>` or `<html>`, because the popups mount inside `<body>`.

## Cascade layers

Name the cascade layer the stylesheet lands in when you import it:

```css
@import '@clerk/mosaic/styles.css' layer(clerk);
```

Layered styles lose to unlayered ones, so any rule in a plain stylesheet beats Mosaic’s.

To order Mosaic against your other layers, declare the order first. Later layers win:

```css
@layer clerk, components, utilities;

@import '@clerk/mosaic/styles.css' layer(clerk);
```

### With Tailwind

List Tailwind’s layers with Mosaic’s between `base` and `components`, so Tailwind’s reset can’t strip Mosaic’s styles and utility classes on a Mosaic component still win:

```css
@layer theme, base, clerk, components, utilities;
@import 'tailwindcss';
@import '@clerk/mosaic/styles.css' layer(clerk);
```

Without a layer, Mosaic’s rules are unlayered and beat Tailwind’s utilities.
