<!--
Source: https://www.theui.dev/docs/time-picker
Part of the theui-svelte documentation. Index: https://www.theui.dev/llms.txt
-->

# Time Picker

The TimePicker component holds the hour, the minute and, in twelve hour mode, AM or PM in separate parts. There is no dropdown to scroll: type the digits, step with the arrow keys or the wheel, and move on. The value is a plain HH:mm string in twenty four hour form, whatever the field shows.

## Example

Import the component and bind a string. Click a part and type, or use the up and down arrows.

```html
<script>
  import { TimePicker } from "theui-svelte";
  let start = $state("09:30")
</script>

<TimePicker bind:value={start}>Start</TimePicker>
```

## Twelve Hour

Add `hour12` for a third part with AM and PM. Press **A** or **P** to set it, or Space to flip it. The value stays in twenty four hour form, so `2:30 PM` is still `"14:30"`.

```html
<TimePicker bind:value={end} hour12>End</TimePicker>

<!-- Rename AM and PM for another language -->
<TimePicker hour12 amLabel="প্রা" pmLabel="অপ" />
```

## Limits and Step

Use `min` and `max`, both `"HH:mm"`, to keep the time inside office hours or any other window; a time outside them is pulled back. The `step` prop is how many minutes the minute part moves at a time.

```html
<TimePicker value="09:00" min="09:00" max="17:00">Office hours</TimePicker>
<TimePicker value="10:15" step={15}>Quarter hours</TimePicker>
```

## Stepper Buttons

Small up and down buttons sit at the end of the field and act on whichever part has focus, or on the minutes when none does. Pass `stepper={false}` to replace them with a clock icon.

```html
<TimePicker value="08:00">With buttons</TimePicker>
<TimePicker value="08:00" stepper={false}>With a clock icon</TimePicker>
```

## Sizes and Variants

The `size` and `variant` props work as on every other field, and are inherited from a [Form](https://www.theui.dev/docs/form) or a [Fieldset](https://www.theui.dev/docs/fieldset).

```html
<TimePicker value="07:05" size="sm" />
<TimePicker value="07:05" size="lg" />
<TimePicker value="07:05" variant="flat" />
<TimePicker value="07:05" rounded="full" />
<TimePicker value="07:05" disabled>Disabled</TimePicker>
```

## In a Form

Give the component a `name` and the `"HH:mm"` value is submitted, the same form a native time input sends. The `onchange` callback runs with every change.

```html
<form method="POST">
  <TimePicker name="startTime" value="09:30" hour12 onchange={(v) => console.log(v)}>
    Start time
  </TimePicker>
  <button>Save</button>
</form>
```

## Animation Speed

The `animationSpeed` prop sets how quickly the field reacts to focus and hover. It takes `"none"`, `"slower"`, `"slow"`, `"normal"`, `"fast"` and `"faster"`, and the default is `"normal"`. Inside a [Form](https://www.theui.dev/docs/form) or a [Fieldset](https://www.theui.dev/docs/fieldset) the value is inherited, so one setting covers every field at once.

```html
<TimePicker animationSpeed="slower">Slower</TimePicker>
<TimePicker animationSpeed="normal">Normal</TimePicker>
<TimePicker animationSpeed="faster">Faster</TimePicker>
<TimePicker animationSpeed="none">No animation</TimePicker>
```

## Reset Styles

Set `reset` to `true` to drop the border, background and focus ring and keep only the classes you pass. The hour, minute and meridiem parts keep their layout, so typing and the arrow keys are unaffected. The default is `false`, and a [Form](https://www.theui.dev/docs/form) or a [Fieldset](https://www.theui.dev/docs/fieldset) can set it for every field it holds.

```html
<TimePicker reset class="w-full border-b-2 border-gray-400 px-1 py-2">
  Underline only
</TimePicker>
```

## Customization

Use `segmentClasses` for the hour, minute and AM/PM parts, `class` for the field itself and `wrapperClasses` for the whole thing.

```html
<TimePicker value="09:30" segmentClasses="text-lg font-semibold" />
<TimePicker value="09:30" hour12 segmentClasses="focus:bg-info-500" class="w-48" />
```

## Keyboard and Wheel

Typing digits fills the part you are in and moves on as soon as nothing more can fit, so `9` in the hour jumps straight to the minutes while `1` waits in case you mean `12`. The up and down arrows step the value and wrap around, and stepping the hour past eleven flips AM to PM. The left and right arrows move between parts, and so does the colon key. Home and End go to the lowest and highest value, and Backspace or Delete empties the part. The wheel steps the part that has focus, so the page still scrolls everywhere else. Pasting `14:30` or `2:30 pm` anywhere in the field fills it.

## Accessibility

Each part is a spin button with its own name, its value and its lowest and highest value, which is what a native time field does, so a screen reader says "Hour, 9" and reads the new number as it changes. The parts sit in a group named by the label, and an empty part is read as "Empty" rather than as the two dashes on screen. The stepper buttons are named Increase and Decrease and are left out of the tab order, since the arrow keys already do the same thing from the keyboard. The value is always kept in twenty four hour form, so what is sent does not depend on what is shown.

## Configuration

### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | string | `` | The chosen time as "HH:mm" in twenty four hour form, whatever the field shows. Bindable with `bind:value`. |
| `min` | string | `00:00` | Earliest time that can be chosen, as "HH:mm". |
| `max` | string | `23:59` | Latest time that can be chosen, as "HH:mm". |
| `step` | number | `1` | How many minutes the minute part moves at a time. |
| `hour12` | boolean | `false` | Shows the hour from 1 to 12 with an AM and PM part. |
| `amLabel` | string | `AM` | Text of the morning half, for another language. |
| `pmLabel` | string | `PM` | Text of the afternoon half, for another language. |
| `stepper` | boolean | `true` | Shows the small up and down buttons. They act on the part that has focus, or on the minutes. |
| `clearable` | boolean | `true` | Shows a button that empties the field once a time is set. |
| `onchange` | (value: string) => void | `undefined` | Runs with the new value every time the time changes. |
| `name` | string | `undefined` | Name of the field, so the "HH:mm" value is submitted with the form. |
| `size` | [INPUT_SIZE](https://www.theui.dev/docs/types#input-size-type) | `md` | Size of the field. Inherited from Form or Fieldset. |
| `variant` | [INPUT_VARIANT](https://www.theui.dev/docs/types#input-variant-type) | `bordered` | Style of the field: "bordered" or "flat". Inherited from Form or Fieldset. |
| `animationSpeed` | [ANIMATE_SPEED](https://www.theui.dev/docs/types#animation-speed-type) | `Inherited from Fieldset or Form, or "normal` | Defines the animation speed for transitions. Available options: "none", "slower", "slow", "normal", "fast", "faster". |
| `reset` | boolean | `Inherited from Fieldset or Form, or false` | Resets all default styles and applies only custom styles. |
| `rounded` | [ROUNDED](https://www.theui.dev/docs/types#rounded-type) | `md` | Defines the border radius of the field. |
| `helperText` | string \| Snippet | `undefined` | Text under the field, linked to the group for screen readers. |
| `labelClasses` | string | `` | Custom classes for the label. |
| `wrapperClasses` | string | `` | Custom classes for the field wrapper. |
| `segmentClasses` | string | `` | Custom classes for the hour, minute and AM/PM parts. |

### Dynamic props

| Name | Description |
| --- | --- |
| `class` | Classes for the field, merged with the default classes. |
| `disabled` | Switches every part off. |
| `readonly` | Shows the time without letting anyone change it. |

### Snippets

| Name | Description |
| --- | --- |
| `children` | Label of the field. |

---

Category: Forms
Keywords: time picker, time input, hour, minute, form, svelte, svelte-5, theui-svelte, component-library, ui, tailwindcss
Full documentation set: https://www.theui.dev/llms-full.txt
