# Separator

Horizontal or vertical dividing line, decorative by default, with an optional label in the middle such as "or".

- Category: Data
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/separator.json
- CLI: `npx markasui@latest add separator`

## When to use

Dividing groups of content in a card, menu, toolbar, or form, such as the "or" between social sign-in and email sign-in.

- Keep it decorative unless the line marks a real boundary between sections
- Use a vertical separator only inside a flex row so it can stretch
- Keep the label to one or two words

## Code

### Blade

Save at `resources/views/components/markas/separator.blade.php`. No extra dependencies.

```blade
@props([
    'orientation' => 'horizontal',
    'decorative' => true,
    'label' => null,
])

@php
    $roots = [
        'horizontal' => 'h-px w-full shrink-0 bg-line',
        'vertical' => 'w-px shrink-0 self-stretch bg-line',
    ];
    $labeledRoots = [
        'horizontal' => 'flex w-full items-center gap-3 text-xs text-muted',
        'vertical' => 'flex shrink-0 flex-col items-center gap-2 self-stretch text-xs text-muted',
    ];
    $lines = [
        'horizontal' => 'h-px flex-1 bg-line',
        'vertical' => 'w-px flex-1 bg-line',
    ];
    $hasLabel = filled($label);
    $semantics = $decorative
        ? ['role' => 'none']
        : array_filter([
            'role' => 'separator',
            'aria-orientation' => $orientation,
            'aria-label' => $hasLabel ? $label : null,
        ]);
@endphp

@if ($hasLabel)
    <div {{ $attributes->merge($semantics)->class([$labeledRoots[$orientation]]) }}><span class="{{ $lines[$orientation] }}"></span><span>{{ $label }}</span><span class="{{ $lines[$orientation] }}"></span></div>
@else
    <div {{ $attributes->merge($semantics)->class([$roots[$orientation]]) }}></div>
@endif
```

```blade
<x-markas.separator />

<div class="flex h-5 items-center gap-3">
    <span>Docs</span>
    <x-markas.separator orientation="vertical" />
    <span>Blog</span>
</div>

<x-markas.separator label="or" />
<x-markas.separator :decorative="false" />
```

### React

Save at `src/components/markas/Separator.tsx`. No extra dependencies.

```tsx
import type { ComponentProps } from "react";

const roots = {
  horizontal: "h-px w-full shrink-0 bg-line",
  vertical: "w-px shrink-0 self-stretch bg-line",
};
const labeledRoots = {
  horizontal: "flex w-full items-center gap-3 text-xs text-muted",
  vertical:
    "flex shrink-0 flex-col items-center gap-2 self-stretch text-xs text-muted",
};
const lines = {
  horizontal: "h-px flex-1 bg-line",
  vertical: "w-px flex-1 bg-line",
};
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

type Orientation = keyof typeof roots;

export type SeparatorProps = Omit<ComponentProps<"div">, "children"> & {
  orientation?: Orientation;
  /** Hanya hiasan visual (role="none"). Matikan bila garis memisahkan bagian yang bermakna. */
  decorative?: boolean;
  /** Teks di tengah garis, misalnya "or". */
  label?: string;
};

export function Separator({
  orientation = "horizontal",
  decorative = true,
  label,
  className,
  ...props
}: SeparatorProps) {
  const semantics = decorative
    ? { role: "none" }
    : {
        role: "separator",
        "aria-orientation": orientation,
        "aria-label": label || undefined,
      };

  if (!label)
    return (
      <div
        {...semantics}
        className={cx(roots[orientation], className)}
        {...props}
      />
    );

  return (
    <div
      {...semantics}
      className={cx(labeledRoots[orientation], className)}
      {...props}
    >
      <span className={lines[orientation]} />
      <span>{label}</span>
      <span className={lines[orientation]} />
    </div>
  );
}
```

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

<Separator />
<div className="flex h-5 items-center gap-3">
  <span>Docs</span>
  <Separator orientation="vertical" />
  <span>Blog</span>
</div>
<Separator label="or" />
<Separator decorative={false} />
```

### Vue

Save at `src/components/markas/Separator.vue`. No extra dependencies.

```vue
<script setup lang="ts">
import { computed } from "vue";

type Orientation = "horizontal" | "vertical";

const props = withDefaults(
  defineProps<{
    orientation?: Orientation;
    decorative?: boolean;
    label?: string;
  }>(),
  { orientation: "horizontal", decorative: true, label: undefined },
);

const roots = {
  horizontal: "h-px w-full shrink-0 bg-line",
  vertical: "w-px shrink-0 self-stretch bg-line",
};
const labeledRoots = {
  horizontal: "flex w-full items-center gap-3 text-xs text-muted",
  vertical:
    "flex shrink-0 flex-col items-center gap-2 self-stretch text-xs text-muted",
};
const lines = {
  horizontal: "h-px flex-1 bg-line",
  vertical: "w-px flex-1 bg-line",
};

const semantics = computed(() =>
  props.decorative
    ? { role: "none" }
    : {
        role: "separator",
        "aria-orientation": props.orientation,
        "aria-label": props.label || undefined,
      },
);
</script>

<template>
  <div
    v-if="props.label"
    v-bind="semantics"
    :class="labeledRoots[props.orientation]"
  >
    <span :class="lines[props.orientation]" />
    <span>{{ props.label }}</span>
    <span :class="lines[props.orientation]" />
  </div>
  <div v-else v-bind="semantics" :class="roots[props.orientation]" />
</template>
```

```vue
<template>
  <Separator />
  <div class="flex h-5 items-center gap-3">
    <span>Docs</span>
    <Separator orientation="vertical" />
    <span>Blog</span>
  </div>
  <Separator label="or" />
  <Separator :decorative="false" />
</template>
```

### Svelte

Save at `src/lib/components/markas/Separator.svelte`. No extra dependencies.

```svelte
<script lang="ts">
  import type { HTMLAttributes } from "svelte/elements";

  const roots = {
    horizontal: "h-px w-full shrink-0 bg-line",
    vertical: "w-px shrink-0 self-stretch bg-line",
  };
  const labeledRoots = {
    horizontal: "flex w-full items-center gap-3 text-xs text-muted",
    vertical:
      "flex shrink-0 flex-col items-center gap-2 self-stretch text-xs text-muted",
  };
  const lines = {
    horizontal: "h-px flex-1 bg-line",
    vertical: "w-px flex-1 bg-line",
  };

  type Orientation = keyof typeof roots;

  type Props = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
    orientation?: Orientation;
    /** Visual only (role="none"). Turn off when the line separates meaningful sections. */
    decorative?: boolean;
    /** Text in the middle of the line, for example "or". */
    label?: string;
  };

  let {
    orientation = "horizontal",
    decorative = true,
    label,
    class: className,
    ...rest
  }: Props = $props();

  const semantics = $derived(
    decorative
      ? { role: "none" as const }
      : {
          role: "separator" as const,
          "aria-orientation": orientation,
          "aria-label": label || undefined,
        },
  );
</script>

{#if label}
  <div {...semantics} class={[labeledRoots[orientation], className]} {...rest}>
    <span class={lines[orientation]}></span>
    <span>{label}</span>
    <span class={lines[orientation]}></span>
  </div>
{:else}
  <div {...semantics} class={[roots[orientation], className]} {...rest}></div>
{/if}
```

```svelte
<script lang="ts">
  import Separator from "$lib/components/markas/Separator.svelte";
</script>

<Separator class="my-4" />
<Separator orientation="vertical" />
<Separator decorative={false} label="Danger zone" />
```

### Astro

Save at `src/components/markas/Separator.astro`. No extra dependencies.

```astro
---
import type { HTMLAttributes } from "astro/types";

const roots = {
  horizontal: "h-px w-full shrink-0 bg-line",
  vertical: "w-px shrink-0 self-stretch bg-line",
};
const labeledRoots = {
  horizontal: "flex w-full items-center gap-3 text-xs text-muted",
  vertical:
    "flex shrink-0 flex-col items-center gap-2 self-stretch text-xs text-muted",
};
const lines = {
  horizontal: "h-px flex-1 bg-line",
  vertical: "w-px flex-1 bg-line",
};

type Orientation = keyof typeof roots;

type Props = HTMLAttributes<"div"> & {
  orientation?: Orientation;
  /** Visual only (role="none"). Turn off when the line separates meaningful sections. */
  decorative?: boolean;
  /** Text in the middle of the line, for example "or". */
  label?: string;
};

const {
  orientation = "horizontal",
  decorative = true,
  label,
  class: className,
  ...rest
} = Astro.props;

const semantics: HTMLAttributes<"div"> = decorative
  ? { role: "none" }
  : {
      role: "separator",
      "aria-orientation": orientation,
      "aria-label": label || undefined,
    };
---

{
  label ? (
    <div
      {...semantics}
      class:list={[labeledRoots[orientation], className]}
      {...rest}
    >
      <span class={lines[orientation]} />
      <span>{label}</span>
      <span class={lines[orientation]} />
    </div>
  ) : (
    <div {...semantics} class:list={[roots[orientation], className]} {...rest} />
  )
}
```

```astro
---
import Separator from "@/components/markas/Separator.astro";
---

<Separator class="my-4" />
<Separator orientation="vertical" />
<Separator decorative={false} label="Danger zone" />
```

### Angular

Save at `src/app/markas/separator.component.ts`. No extra dependencies.

```ts
import {
  booleanAttribute,
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
} from "@angular/core";

const roots = {
  horizontal: "h-px w-full shrink-0 bg-line",
  vertical: "w-px shrink-0 self-stretch bg-line",
};
const labeledRoots = {
  horizontal: "flex w-full items-center gap-3 text-xs text-muted",
  vertical:
    "flex shrink-0 flex-col items-center gap-2 self-stretch text-xs text-muted",
};
const lines = {
  horizontal: "h-px flex-1 bg-line",
  vertical: "w-px flex-1 bg-line",
};

export type SeparatorOrientation = keyof typeof roots;

/**
 * Attribute selector on a native div: the user's class and attributes stay on the line itself.
 * Usage: `<div markas-separator orientation="vertical"></div>`.
 */
@Component({
  selector: "div[markas-separator]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    "[class]": "classes()",
    "[attr.role]": "decorative() ? 'none' : 'separator'",
    "[attr.aria-orientation]": "decorative() ? null : orientation()",
    "[attr.aria-label]": "decorative() ? null : label() || null",
  },
  template: `
    @if (label()) {
      <span [class]="line()"></span>
      <span>{{ label() }}</span>
      <span [class]="line()"></span>
    }
  `,
})
export class Separator {
  readonly orientation = input<SeparatorOrientation>("horizontal");
  /** Visual only (role="none"). Turn off when the line separates meaningful sections. */
  readonly decorative = input(true, { transform: booleanAttribute });
  /** Text in the middle of the line, for example "or". */
  readonly label = input<string>();

  protected readonly line = computed(() => lines[this.orientation()]);
  protected readonly classes = computed(() =>
    this.label() ? labeledRoots[this.orientation()] : roots[this.orientation()],
  );
}
```

```ts
import { Component } from "@angular/core";
import { Separator } from "./markas/separator.component";

@Component({
  selector: "app-example",
  imports: [Separator],
  template: `
    <div markas-separator class="my-4"></div>
    <div markas-separator orientation="vertical"></div>
    <div markas-separator [decorative]="false" label="Danger zone"></div>
  `,
})
export class Example {}
```

Angular uses an attribute selector on a native `div`.

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `orientation` | `'horizontal' \| 'vertical'` | horizontal | Direction of the line. A vertical separator stretches to the height of its flex parent. |
| `decorative` | `boolean` | true | Purely visual line with role=none. Set to false when the line separates meaningful sections, which adds role=separator and aria-orientation. |
| `label` | `string` | - | Short text in the middle of the line, such as "or". |

## Accessibility

- Decorative separators use role=none so screen readers skip them.
- With decorative=false the element gets role=separator and aria-orientation; a label also becomes its aria-label.
- The label text uses muted, which meets AA contrast in light and dark mode.

## Notes

- No JavaScript needed. The Blade version does not need Alpine.js.
- A vertical separator uses `self-stretch`, so place it inside a flex row with a height.
- Add spacing with a class, such as `class="my-4"`.
- The component has no built-in text. Pass `label` in the language of your site.
