# Day Separator (/docs/agent-ui/components/day-separator)

Use a day separator before the first message of each day, so a long conversation shows when things were said. It's a heading, so screen reader users can jump from one day to the next.

<Example caption="Each day starts with a heading. Recent days read Today, Yesterday or their weekday, and older ones read their date.">
  <DaySeparatorExample />

  ```tsx tab="React"
  import { dayKey } from "@kind-ui/agent-ui/core";
  import {
    Conversation,
    ConversationContent,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/conversation";
  import { DaySeparator } from "@/components/ui/day-separator";

  const timeZone = "America/Los_Angeles";

  const messages = [
    {
      id: "m1",
      role: "user",
      createdAt: "2026-11-16T17:40:00Z",
      text: "Can you check why the nightly export failed?",
    },
    {
      id: "m2",
      role: "assistant",
      createdAt: "2026-11-16T17:41:00Z",
      text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
    },
    { id: "m3", role: "user", createdAt: "2026-11-17T16:05:00Z", text: "Did last night's run go through?" },
    {
      id: "m4",
      role: "assistant",
      createdAt: "2026-11-17T16:06:00Z",
      text: "Yes. It retried two pages and finished in 48 minutes.",
    },
  ];

  type Row = { id: string; date: string } | { id: string; message: (typeof messages)[number] };

  const rows = messages.flatMap((message, index): Row[] => {
    const day = dayKey(message.createdAt, timeZone);
    const previous = messages[index - 1];
    const newDay = !previous || dayKey(previous.createdAt, timeZone) !== day;
    return newDay
      ? [
          { id: `day-${day}`, date: message.createdAt },
          { id: message.id, message },
        ]
      : [{ id: message.id, message }];
  });

  export default function DaySeparatorExample() {
    return (
      <Conversation
        aria-label="Conversation"
        messageCount={rows.length}
        className="h-80 w-full max-w-xl rounded-xl border border-[var(--kind-color-border)]"
      >
        <ConversationViewport>
          <ConversationContent>
            {rows.map((row, index) => (
              <ConversationRow key={row.id} value={row.id} index={index}>
                {"message" in row ? (
                  <p
                    className={
                      row.message.role === "user"
                        ? "ms-auto w-fit max-w-[80%] rounded-2xl bg-[var(--kind-color-hover)] px-3.5 py-2"
                        : undefined
                    }
                  >
                    {row.message.text}
                  </p>
                ) : (
                  <DaySeparator date={row.date} timeZone={timeZone} />
                )}
              </ConversationRow>
            ))}
          </ConversationContent>
        </ConversationViewport>
      </Conversation>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import { dayKey } from "@kind-ui/agent-ui/core";
  import {
    Conversation,
    ConversationContent,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/vue/conversation";
  import { DaySeparator } from "@/components/ui/vue/day-separator";

  const timeZone = "America/Los_Angeles";

  const messages = [
    {
      id: "m1",
      role: "user",
      createdAt: "2026-11-16T17:40:00Z",
      text: "Can you check why the nightly export failed?",
    },
    {
      id: "m2",
      role: "assistant",
      createdAt: "2026-11-16T17:41:00Z",
      text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
    },
    { id: "m3", role: "user", createdAt: "2026-11-17T16:05:00Z", text: "Did last night's run go through?" },
    {
      id: "m4",
      role: "assistant",
      createdAt: "2026-11-17T16:06:00Z",
      text: "Yes. It retried two pages and finished in 48 minutes.",
    },
  ];

  type Row = { id: string; date: string } | { id: string; message: (typeof messages)[number] };

  const rows = messages.flatMap((message, index): Row[] => {
    const day = dayKey(message.createdAt, timeZone);
    const previous = messages[index - 1];
    const newDay = !previous || dayKey(previous.createdAt, timeZone) !== day;
    return newDay
      ? [
          { id: `day-${day}`, date: message.createdAt },
          { id: message.id, message },
        ]
      : [{ id: message.id, message }];
  });
  </script>

  <template>
    <Conversation
      aria-label="Conversation"
      :message-count="rows.length"
      class="h-80 w-full max-w-xl rounded-xl border border-[var(--kind-color-border)]"
    >
      <ConversationViewport>
        <ConversationContent>
          <ConversationRow v-for="(row, index) in rows" :key="row.id" :value="row.id" :index="index">
            <p
              v-if="'message' in row"
              :class="
                row.message.role === 'user'
                  ? 'ms-auto w-fit max-w-[80%] rounded-2xl bg-[var(--kind-color-hover)] px-3.5 py-2'
                  : undefined
              "
            >
              {{ row.message.text }}
            </p>
            <DaySeparator v-else :date="row.date" :time-zone="timeZone" />
          </ConversationRow>
        </ConversationContent>
      </ConversationViewport>
    </Conversation>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import { dayKey } from "@kind-ui/agent-ui/core";
    import {
      Conversation,
      ConversationContent,
      ConversationRow,
      ConversationViewport,
    } from "@/components/ui/svelte/conversation/index.js";
    import { DaySeparator } from "@/components/ui/svelte/day-separator/index.js";

    const timeZone = "America/Los_Angeles";

    const messages = [
      {
        id: "m1",
        role: "user",
        createdAt: "2026-11-16T17:40:00Z",
        text: "Can you check why the nightly export failed?",
      },
      {
        id: "m2",
        role: "assistant",
        createdAt: "2026-11-16T17:41:00Z",
        text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
      },
      { id: "m3", role: "user", createdAt: "2026-11-17T16:05:00Z", text: "Did last night's run go through?" },
      {
        id: "m4",
        role: "assistant",
        createdAt: "2026-11-17T16:06:00Z",
        text: "Yes. It retried two pages and finished in 48 minutes.",
      },
    ];

    type Row = { id: string; date: string } | { id: string; message: (typeof messages)[number] };

    const rows = messages.flatMap((message, index): Row[] => {
      const day = dayKey(message.createdAt, timeZone);
      const previous = messages[index - 1];
      const newDay = !previous || dayKey(previous.createdAt, timeZone) !== day;
      return newDay
        ? [
            { id: `day-${day}`, date: message.createdAt },
            { id: message.id, message },
          ]
        : [{ id: message.id, message }];
    });
  </script>

  <Conversation
    aria-label="Conversation"
    messageCount={rows.length}
    class="h-80 w-full max-w-xl rounded-xl border border-[var(--kind-color-border)]"
  >
    <ConversationViewport>
      <ConversationContent>
        {#each rows as row, index (row.id)}
          <ConversationRow value={row.id} {index}>
            {#if "message" in row}
              <p
                class={row.message.role === "user"
                  ? "ms-auto w-fit max-w-[80%] rounded-2xl bg-[var(--kind-color-hover)] px-3.5 py-2"
                  : undefined}
              >
                {row.message.text}
              </p>
            {:else}
              <DaySeparator date={row.date} {timeZone} />
            {/if}
          </ConversationRow>
        {/each}
      </ConversationContent>
    </ConversationViewport>
  </Conversation>
  ```

  ```tsx tab="Solid"
  import { dayKey } from "@kind-ui/agent-ui/core";
  import { For, Show } from "solid-js";
  import {
    Conversation,
    ConversationContent,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/solid/conversation";
  import { DaySeparator } from "@/components/ui/solid/day-separator";

  const timeZone = "America/Los_Angeles";

  const messages = [
    {
      id: "m1",
      role: "user",
      createdAt: "2026-11-16T17:40:00Z",
      text: "Can you check why the nightly export failed?",
    },
    {
      id: "m2",
      role: "assistant",
      createdAt: "2026-11-16T17:41:00Z",
      text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
    },
    { id: "m3", role: "user", createdAt: "2026-11-17T16:05:00Z", text: "Did last night's run go through?" },
    {
      id: "m4",
      role: "assistant",
      createdAt: "2026-11-17T16:06:00Z",
      text: "Yes. It retried two pages and finished in 48 minutes.",
    },
  ];

  type Row = { id: string; date?: string; message?: (typeof messages)[number] };

  const rows = messages.flatMap((message, index): Row[] => {
    const day = dayKey(message.createdAt, timeZone);
    const previous = messages[index - 1];
    const newDay = !previous || dayKey(previous.createdAt, timeZone) !== day;
    return newDay
      ? [
          { id: `day-${day}`, date: message.createdAt },
          { id: message.id, message },
        ]
      : [{ id: message.id, message }];
  });

  export default function DaySeparatorExample() {
    return (
      <Conversation
        aria-label="Conversation"
        messageCount={rows.length}
        class="h-80 w-full max-w-xl rounded-xl border border-[var(--kind-color-border)]"
      >
        <ConversationViewport>
          <ConversationContent>
            <For each={rows} keyed={(row) => row.id}>
              {(row, index) => (
                <ConversationRow value={row().id} index={index()}>
                  <Show when={row().message} fallback={<DaySeparator date={row().date} timeZone={timeZone} />}>
                    {(message) => (
                      <p
                        class={
                          message().role === "user"
                            ? "ms-auto w-fit max-w-[80%] rounded-2xl bg-[var(--kind-color-hover)] px-3.5 py-2"
                            : undefined
                        }
                      >
                        {message().text}
                      </p>
                    )}
                  </Show>
                </ConversationRow>
              )}
            </For>
          </ConversationContent>
        </ConversationViewport>
      </Conversation>
    );
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/day-separator
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/day-separator-web
```

```bash tab="Vue"
npx shadcn@latest add @kind-ui/day-separator-vue
```

```bash tab="Svelte"
npx shadcn@latest add @kind-ui/day-separator-svelte
```

```bash tab="Solid"
npx shadcn@latest add @kind-ui/day-separator-solid
```

## Composition [#composition]

```text
DaySeparator
└── DaySeparatorLabel
```

The root is the heading, with a line on each side drawn in CSS. `DaySeparatorLabel` renders a `<time>` whose `datetime` is the day as `YYYY-MM-DD`, and shows the day in words unless you pass children. `DaySeparator` renders its label when you pass none.

## Usage [#usage]

### Date [#date]

Pass `date`, an ISO date (`"2026-11-18"`) or date-time (`"2026-11-18T17:40:00Z"`). `timeZone` decides which day a date-time falls on, and which day is today, so pass the reader's zone. It's UTC by default.

In the browser, the heading reads "Today", "Yesterday", its weekday up to 6 days back, and its date before that. Server markup always shows the date ("November 18, 2026"), and the words change once the page loads, so hydration never mismatches. A page left open past midnight moves "Today" to "Yesterday" on its own. Pass `relative={false}` to always show the date.

The day reads in `locale`, else the page's language, else English. The heading is level 3; pass `level` (1 to 6) to fit it into your page's outline.

### Between Messages [#between-messages]

Put a separator before each message whose day differs from the previous message's. `dayKey` turns a `createdAt` into the day it falls on in a time zone:

```tsx
import { dayKey } from "@kind-ui/agent-ui/core";

{messages.map((message, index) => {
  const previous = messages[index - 1];
  const newDay =
    !previous || dayKey(previous.createdAt, timeZone) !== dayKey(message.createdAt, timeZone);
  return (
    <Fragment key={message.id}>
      {newDay && <DaySeparator date={message.createdAt} timeZone={timeZone} />}
      <MessageView message={message} />
    </Fragment>
  );
})}
```

Pass the same `timeZone` to `dayKey` and the separator, so the day you split on is the day the heading names. In a [virtualized conversation](./conversation.mdx), make each separator its own row, as the example does, so it's measured like any other.

## API Reference [#api-reference]

### DaySeparatorOptions

| Prop        | Type                   | Description                                                                                                                            |
| ----------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `date?`     | `string \| undefined`  | The day the heading names: an ISO date (`"2026-11-18"`) or date-time, read in `timeZone`. Without a valid one the heading is `hidden`. |
| `locale?`   | `string \| undefined`  | A BCP 47 tag the day reads in. Defaults to the page's language in the browser, and English on the server.                              |
| `timeZone?` | `string \| undefined`  | The IANA time zone that decides which day a date-time falls on, and which day is today. Default: `"UTC"`                               |
| `level?`    | `number \| undefined`  | The heading level, 1 to 6. Anything else reads as 3. Default: `3`                                                                      |
| `relative?` | `boolean \| undefined` | Whether a recent day reads "Today", "Yesterday" or its weekday in the browser. Server markup always shows the date. Default: `true`    |

### Agent [#agent]

A day separator is content, so it offers an agent connected with `createAgent` no actions.

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. Call `defineDaySeparator()`, then write `<kind-day-separator date="2026-11-18" time-zone="America/Los_Angeles">`: each prop is a kebab-case attribute, so `timeZone` is `time-zone`. The element fills in its label when it has no children, and leaves text you wrote into a `<kind-day-separator-label>` alone.
</Caption>
