# Overlay

Content layered over media on hover, focus, or persistently.

Content layered over media on hover, focus, or persistently.

```tsx
import { Button, Overlay, Stack } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function OverlayExample() {
  return (
    <Overlay
      showOn="hover"
      position="bottom"
      className="w-full max-w-lg"
      content={
        <Stack gap="2" align="start">
          <div>
            <p className="type-body-m font-bold">Moraine Lake</p>
            <p className="type-body-s opacity-80">Banff at sunrise</p>
          </div>
          <Button size="sm" variant="secondary">
            Quick view
          </Button>
        </Stack>
      }
    >
      <img
        src={thumbnailPhotos.moraineLake.src}
        alt={thumbnailPhotos.moraineLake.alt}
        className="aspect-[8/5] w-full object-cover"
      />
    </Overlay>
  );
}
```

The examples use photographs from Unsplash by [ConfinedRiley](https://unsplash.com/photos/a-lake-surrounded-by-mountains-mIj8Cn3oNDg), [Tim G](https://unsplash.com/photos/snow-capped-mountains-reflected-in-a-calm-lake-BrFSOHMGuak), and [Sebastian Schuster](https://unsplash.com/photos/modern-building-exterior-with-strong-geometric-shadows-A-13PmQkP1o).

## Anatomy

Overlay keeps the base surface and its layered content in one bounded stacking context.

```tsx
<Overlay position="bottom" showOn="hover" content={<span>Workspace overview</span>}>
  <img src="/workspace.png" alt="Workspace dashboard" />
</Overlay>
```

## Import

```tsx
import { Overlay } from "@zentara-co/zenos-ui";
```

Overlay layers short content or actions over a bounded surface. It does not create a modal, portal, focus trap, or page backdrop.

## Visibility

`hover` also reveals when focus enters the overlay so keyboard users can reach its content. Use `focus` when pointer hover should not expose the layer, and `always` for persistent captions or controls. `hover-or-focus` remains a backwards-compatible alias for `hover`.

```tsx
import { Grid, Overlay } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function OverlayVisibilityExample() {
  const examples = [
    { showOn: "always", label: "Always visible", photo: thumbnailPhotos.moraineLake },
    { showOn: "hover", label: "Hover or focus", photo: thumbnailPhotos.lakeMatheson },
    { showOn: "focus", label: "Focus only", photo: thumbnailPhotos.architecture },
  ] as const;

  return (
    <Grid columns={{ base: 1, md: 3 }} gap="4" className="w-full">
      {examples.map(({ showOn, label, photo }) => (
        <Overlay
          key={showOn}
          showOn={showOn}
          position="bottom"
          content={<span className="type-body-s font-medium">{label}</span>}
        >
          <img src={photo.src} alt={photo.alt} className="aspect-[4/3] w-full object-cover" />
        </Overlay>
      ))}
    </Grid>
  );
}
```

## Position

`position="fill"` uses a uniform layer. `top` and `bottom` use directional fades that remain strongest beside the content and reveal more of the media toward the opposite edge. Use `align="start"` with top content and `align="end"` with bottom content.

```tsx
import { Grid, Overlay } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function OverlayPositionExample() {
  const positions = [
    { position: "top", photo: thumbnailPhotos.moraineLake },
    { position: "fill", photo: thumbnailPhotos.lakeMatheson },
    { position: "bottom", photo: thumbnailPhotos.architecture },
  ] as const;

  return (
    <Grid columns={{ base: 1, md: 3 }} gap="4" className="w-full">
      {positions.map(({ position, photo }) => (
        <Overlay
          key={position}
          position={position}
          align={position === "top" ? "start" : position === "fill" ? "center" : "end"}
          content={<span className="type-body-s font-medium capitalize">{position}</span>}
        >
          <img src={photo.src} alt={photo.alt} className="aspect-[4/3] w-full object-cover" />
        </Overlay>
      ))}
    </Grid>
  );
}
```

## Scrim

Dark and light scrims keep their visual polarity in both color schemes, so their foreground color remains predictable. Nested content should inherit the scrim color; when using a component with its own color prop, explicitly choose a color that contrasts with the selected scrim. Use `scrim={false}` only when custom content supplies its own readable surface.

```tsx
import { Grid, Overlay } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function OverlayScrimExample() {
  return (
    <Grid columns={{ base: 1, sm: 2 }} gap="4" className="w-full max-w-2xl">
      <Overlay
        scrim="dark"
        align="center"
        content={<span className="type-body-m font-medium">Dark scrim</span>}
      >
        <img
          src={thumbnailPhotos.moraineLake.src}
          alt={thumbnailPhotos.moraineLake.alt}
          className="aspect-[8/5] w-full object-cover"
        />
      </Overlay>
      <Overlay
        scrim="light"
        align="center"
        content={<span className="type-body-m font-medium">Light scrim</span>}
      >
        <img
          src={thumbnailPhotos.architecture.src}
          alt={thumbnailPhotos.architecture.alt}
          className="aspect-[8/5] w-full object-cover"
        />
      </Overlay>
    </Grid>
  );
}
```

## Controlled visibility

Supply `open` when another control owns visibility and update it from `onOpenChange`. A closed controlled overlay becomes inert so hidden actions cannot receive focus. Touching a non-interactive area requests the next controlled state through `onOpenChange`.

```tsx
import { Button, Overlay, Stack } from "@zentara-co/zenos-ui";
import { useState } from "react";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function OverlayControlledExample() {
  const [open, setOpen] = useState(false);
  return (
    <Stack gap="4" align="center" className="w-full max-w-md">
      <Button variant="primary" onClick={() => setOpen((current) => !current)}>
        {open ? "Hide details" : "Show details"}
      </Button>
      <Overlay
        open={open}
        onOpenChange={setOpen}
        showOn="hover"
        position="bottom"
        className="w-full"
        align="center"
        content={
          <Stack gap="2" align="center">
            <span className="type-body-m font-medium">Landscape details are visible</span>
            <Button size="sm" variant="secondary" onClick={() => setOpen(false)}>
              Close details
            </Button>
          </Stack>
        }
      >
        <img
          src={thumbnailPhotos.lakeMatheson.src}
          alt={thumbnailPhotos.lakeMatheson.alt}
          className="aspect-[8/5] w-full object-cover"
        />
      </Overlay>
    </Stack>
  );
}
```

## Custom styling

Use `className` for the bounded root and `contentClassName` for the positioned layer. This keeps layout customization separate from the media and lets a custom panel replace the built-in scrim without rebuilding visibility behavior. Pair semantic surface, border, and foreground tokens so the treatment maintains contrast in both light and dark modes; nested components with their own color styles should use the same foreground family.

```tsx
import { Overlay, Stack, Text } from "@zentara-co/zenos-ui";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function OverlayCustomExample() {
  return (
    <Overlay
      position="bottom"
      scrim={false}
      className="w-full max-w-lg"
      contentClassName="inset-x-3 bottom-3 min-h-0 rounded-lg border border-border-accent-purple-default bg-background-accent-purple-subtlest-default p-3 text-text-accent-purple-bolder shadow-overlay"
      content={
        <Stack gap="1">
          <Text weight="bold" className="text-text-accent-purple-bolder">
            Architectural study
          </Text>
          <Text size="s" className="text-text-accent-purple-bolder opacity-80">
            Minimal form · Light and shadow
          </Text>
        </Stack>
      }
    >
      <img
        src={thumbnailPhotos.architecture.src}
        alt={thumbnailPhotos.architecture.alt}
        className="aspect-[8/5] w-full object-cover"
      />
    </Overlay>
  );
}
```

## Overlay or another component

Use Overlay for content that remains physically attached to a media or card surface. Use [Popover](/components/popover/) for anchored floating content, [Dialog](/components/dialog/) for modal tasks, and [Lightbox](/components/lightbox/) for fullscreen media viewing.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| content | ReactNode | — | Content shown over children. |
| contentClassName | string | — | Adds classes to the positioned content layer. |
| showOn | OverlayShowOn | always | Visibility interaction; hover also reveals on focus for keyboard access. |
| scrim | dark \| light \| false | dark | Theme-independent dark, light, or consumer-styled backdrop treatment. |
| position | fill \| top \| bottom | fill | Uniform fill or directional top/bottom fade placement. |
| align | start \| center \| end | end | Vertical content alignment within the positioned layer. |
| open | boolean | — | Controlled visibility override. |
| defaultOpen | boolean | false | Initial touch visibility for uncontrolled usage. |
| onOpenChange | (open: boolean) => void | — | Runs when touch interaction requests a visibility change. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Overlay preserves the semantics of its children and content. Hover-revealed content also appears on `focus-within`, and controlled hidden content is inert. Keep essential information available without hover, provide meaningful alternative text for media, and maintain sufficient contrast for custom scrims. Touch taps toggle revealable overlays unless the tap targets an interactive element.

Source: https://zenos-ui.pages.dev/components/overlay/