# Separator

A thin line that divides content, with an optional label.

A 1px rule in the line colour that divides content, horizontal or vertical. An optional label sits in the middle with a rule on each side, like the "or" between two ways of signing in. It takes no room of its own: the caller spaces it. The model is the shared option separator and the rules between menu groups.

Kind: component · Category: Display · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add separator
```

It writes the folder `separator/` into the project's ui folder (`index.ts`, `separator.tsx`, `Separator.vue`, `Separator.svelte`, `separator.recipe.ts`). First time: [Installation](/installation.md).

## Usage

```tsx
import { Separator } from "@/components/ui/separator";
```

```vue
import { Separator } from "@/components/ui/separator";
```

```svelte
import { Separator } from "$lib/components/ui/separator";
```

## Parts

In the DOM the root carries `data-slot="separator"` and each part `data-slot="separator-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `separator` |  | role="separator" with aria-orientation, or role="none" when decorative. Without a label the element is the rule (1px, color.line): full width when horizontal, stretched to its row when vertical. With a label it is a flex row (a column when vertical) whose ::before and ::after are the two rules. |
| `label` | `span` | `separator-label` | optional | The text in the middle (the children): text.xs, ink-2, centred. It wraps, never truncates, and takes at most 70% of the line (of the height when vertical), so the two rules share the rest. Author text keeps its own direction. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | horizontal: 1px high, as wide as its container. vertical: 1px wide, as tall as the row it sits in (align-self: stretch); outside a flex row give it a height. |
| `decorative` | `boolean` | `false` | Purely visual: role="none", so assistive technology skips it (a label is then read as plain text). Otherwise role="separator" with aria-orientation, named by its label when it has one. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Slots

| Slot | Content |
| --- | --- |
| `default` | Label in the middle (optional). |

## Keyboard and accessibility

Role: separator.

Notes:

- role="separator" with aria-orientation (horizontal or vertical); role="none" when decorative.
- A separator's children are presentational, so a labelled one is named by its label (aria-labelledby) and the label is announced once, as the separator's name.
- Not focusable: this is the static separator, not a splitter.

## Motion

- none

## Tokens

`color.line`, `color.ink-2`, `text.xs`

## Examples

### Between settings sections

React · `settings-sections.tsx`

```tsx
import { Separator } from "@/components/ui/separator";

export default function SettingsSections() {
  return (
    <div className="flex w-72 flex-col gap-3 text-sm">
      <div>
        <p className="font-medium text-ink">Project name</p>
        <p className="text-ink-2">web-app, used in preview URLs and the CLI.</p>
      </div>
      <Separator />
      <div>
        <p className="font-medium text-ink">Production branch</p>
        <p className="text-ink-2">Pushes to main deploy to Production.</p>
      </div>
    </div>
  );
}
```

Vue · `settings-sections.vue`

```vue
<script setup lang="ts">
import { Separator } from "@/components/ui/separator";
</script>

<template>
  <div class="flex w-72 flex-col gap-3 text-sm">
    <div>
      <p class="font-medium text-ink">Project name</p>
      <p class="text-ink-2">web-app, used in preview URLs and the CLI.</p>
    </div>
    <Separator />
    <div>
      <p class="font-medium text-ink">Production branch</p>
      <p class="text-ink-2">Pushes to main deploy to Production.</p>
    </div>
  </div>
</template>
```

Svelte · `settings-sections.svelte`

```svelte
<script lang="ts">
  import { Separator } from "$lib/components/ui/separator";
</script>

<div class="flex w-72 flex-col gap-3 text-sm">
  <div>
    <p class="font-medium text-ink">Project name</p>
    <p class="text-ink-2">web-app, used in preview URLs and the CLI.</p>
  </div>
  <Separator />
  <div>
    <p class="font-medium text-ink">Production branch</p>
    <p class="text-ink-2">Pushes to main deploy to Production.</p>
  </div>
</div>
```

### In a deploy's details line

React · `deploy-details.tsx`

```tsx
import { Separator } from "@/components/ui/separator";

/* vertical: as tall as the row it sits in; decorative, the values read fine without it */
export default function DeployDetails() {
  return (
    <div className="flex h-5 items-center gap-3 text-sm text-ink-2">
      <span>dpl_7f3a9c</span>
      <Separator orientation="vertical" decorative />
      <span>main</span>
      <Separator orientation="vertical" decorative />
      <span>a1b2c3d</span>
      <Separator orientation="vertical" decorative />
      <span>2 min ago</span>
    </div>
  );
}
```

Vue · `deploy-details.vue`

```vue
<script setup lang="ts">
import { Separator } from "@/components/ui/separator";
</script>

<!-- vertical: as tall as the row it sits in; decorative, the values read fine without it -->
<template>
  <div class="flex h-5 items-center gap-3 text-sm text-ink-2">
    <span>dpl_7f3a9c</span>
    <Separator orientation="vertical" decorative />
    <span>main</span>
    <Separator orientation="vertical" decorative />
    <span>a1b2c3d</span>
    <Separator orientation="vertical" decorative />
    <span>2 min ago</span>
  </div>
</template>
```

Svelte · `deploy-details.svelte`

```svelte
<script lang="ts">
  import { Separator } from "$lib/components/ui/separator";
</script>

<!-- vertical: as tall as the row it sits in; decorative, the values read fine without it -->
<div class="flex h-5 items-center gap-3 text-sm text-ink-2">
  <span>dpl_7f3a9c</span>
  <Separator orientation="vertical" decorative />
  <span>main</span>
  <Separator orientation="vertical" decorative />
  <span>a1b2c3d</span>
  <Separator orientation="vertical" decorative />
  <span>2 min ago</span>
</div>
```

### Between sign-in options

React · `sign-in-options.tsx`

```tsx
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";

export default function SignInOptions() {
  return (
    <div className="flex w-72 flex-col gap-3">
      <Button variant="primary">Continue with email</Button>
      <Separator>or</Separator>
      <Button>Continue with single sign-on</Button>
    </div>
  );
}
```

Vue · `sign-in-options.vue`

```vue
<script setup lang="ts">
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
</script>

<template>
  <div class="flex w-72 flex-col gap-3">
    <Button variant="primary">Continue with email</Button>
    <Separator>or</Separator>
    <Button>Continue with single sign-on</Button>
  </div>
</template>
```

Svelte · `sign-in-options.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { Separator } from "$lib/components/ui/separator";
</script>

<div class="flex w-72 flex-col gap-3">
  <Button variant="primary">Continue with email</Button>
  <Separator>or</Separator>
  <Button>Continue with single sign-on</Button>
</div>
```

## Recipe

`separator.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* separator — a 1px rule in the line colour, horizontal or vertical, with an optional label in the
 * middle (the "or" of a sign-in form). The model is the shared option separator and the rules
 * between menu groups (lib/option.ts: h-px bg-line); it takes no margin of its own, the caller spaces it.
 *
 * Without a label the element is the rule. With one (`labelled`, set by the adapter when it has
 * children) the element is a flex line whose ::before and ::after are the two rules, so the label
 * part is the only child. The label wraps rather than being cut; it takes at most 70% of the line
 * (a column: of the height), so the rules keep the rest, and nothing overflows when narrow. */
export const separator = tv({
  slots: {
    base: "shrink-0 border-0 bg-line",
    label: "min-w-0 text-center text-xs leading-4 text-ink-2 wrap-anywhere [unicode-bidi:plaintext]",
  },
  variants: {
    orientation: {
      horizontal: { base: "h-px w-full" },
      /* as tall as the row it sits in; h-full when its parent has a height of its own */
      vertical: { base: "w-px h-full self-stretch" },
    },
    labelled: {
      true: {
        base: [
          "flex items-center bg-transparent",
          "before:content-[''] before:flex-1 before:bg-line after:content-[''] after:flex-1 after:bg-line",
        ],
      },
    },
  },
  compoundVariants: [
    { orientation: "horizontal", labelled: true, class: { base: "h-auto gap-3 before:h-px after:h-px", label: "max-w-[70%]" } },
    { orientation: "vertical", labelled: true, class: { base: "w-auto flex-col gap-2 before:w-px after:w-px", label: "max-h-[70%]" } },
  ],
  defaultVariants: { orientation: "horizontal", labelled: false },
});

export type SeparatorRecipeProps = VariantProps<typeof separator>;
```
