---
title: "Slider Area"
description: "A two-dimensional input where the user selects a point within a given region."
canonical_url: "https://vinicunca.dev/akar/components/slider-area"
---
# Slider Area

> A two-dimensional input where the user selects a point within a given region.

```vue [AkarDemoSliderArea.vue]
<script setup lang="ts">
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar';
import { ref } from 'vue';
import './styles.css';

const sliderValue = ref([
  [50, 50],
]);
</script>

<template>
  <div class="akar-demo akar-demo-SliderArea">
    <SliderAreaRoot
      v-model="sliderValue"
      class="SliderAreaRoot"
    >
      <SliderAreaArea class="SliderAreaArea">
        <SliderAreaRegion class="SliderAreaRegion" />
      </SliderAreaArea>
      <SliderAreaThumb
        class="SliderAreaThumb"
        aria-label="Position"
      />
    </SliderAreaRoot>
  </div>
</template>
```

```css [styles.css]
@import '../_colors/black-alpha.css';
@import '../_colors/grass.css';

@scope (.akar-demo-SliderArea) {
  .SliderAreaRoot {
    position: relative;
    display: block;
    user-select: none;
    touch-action: none;
    width: 200px;
    height: 200px;
  }

  .SliderAreaArea {
    background-color: var(--ui-color-bg-accented);
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 6px;
  }

  .SliderAreaRegion {
    background-color: var(--ui-color-primary);
    opacity: 0.35;
    border-radius: 4px;
  }

  .SliderAreaThumb {
    display: block;
    width: 20px;
    height: 20px;
    background-color: var(--ui-color-bg);
    border: 1px solid var(--ui-color-border);
    box-shadow: 0 2px 10px var(--black-a7);
    border-radius: 10px;
  }
  .SliderAreaThumb:hover {
    background-color: var(--grass-3);
  }
  .SliderAreaThumb:focus-visible {
    outline: none;
    box-shadow: 0 0 0 5px var(--grass-7);
  }
}
```

## Features

- Can be controlled or uncontrolled.
- Supports multiple thumbs.
- Supports touch or click on track to update value.
- Supports Right to Left direction.
- Full keyboard navigation.
- Separate X and Y axis configuration.

## Installation

Install the component from your command line.

```bash [pnpm]
pnpm add akar
```

```bash [yarn]
yarn add akar
```

```bash [npm]
npm install akar
```

```bash [bun]
bun add akar
```

## Anatomy

Import all parts and piece them together.

```vue
<script setup>
import {
  SliderAreaArea,
  SliderAreaRegion,
  SliderAreaRoot,
  SliderAreaThumb,
} from 'akar';
</script>

<template>
  <SliderAreaRoot>
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

## API Reference

### Root

Contains all the parts of a slider area. It will render an `input` when used within a `form` to ensure events propagate correctly.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |
| `defaultValue` | `[<br>    [0, 0],<br>] as Array<Array<number>>` | `number[][]` | The value of the slider area when initially rendered. Use when you do not need to control the state. |
| `dir` |  | `"ltr" \| "rtl"` | The reading direction. If omitted, inherits globally from `ConfigProvider` or assumes LTR. |
| `disabled` | `false` | `boolean` | When `true`, prevents the user from interacting with the slider area. |
| `invertedX` | `false` | `boolean` | Whether the X axis is visually inverted. |
| `invertedY` | `false` | `boolean` | Whether the Y axis is visually inverted. |
| `maxX` | `100` | `number` | The maximum value for the X axis. |
| `maxY` | `100` | `number` | The maximum value for the Y axis. |
| `minX` | `0` | `number` | The minimum value for the X axis. |
| `minXStepsBetweenThumbs` | `0` | `number` | The minimum permitted steps between multiple thumbs on the X axis. |
| `minY` | `0` | `number` | The minimum value for the Y axis. |
| `minYStepsBetweenThumbs` | `0` | `number` | The minimum permitted steps between multiple thumbs on the Y axis. |
| `modelValue` |  | `number[][] \| null` | The controlled value of the slider area. Can be bind as `v-model`. |
| `name` |  | `string` | The name of the field. Submitted with its owning form as part of a name/value pair. |
| `required` |  | `boolean` | When `true`, indicates that the user must set the value before the owning form can be submitted. |
| `stepX` | `1` | `number` | The stepping interval for the X axis. |
| `stepY` | `1` | `number` | The stepping interval for the Y axis. |
| `thumbAlignment` | `"overflow"` | `"overflow" \| "contain"` | The alignment of the slider area thumb.<br>- `contain`: thumbs will be contained within the bounds of the track.<br>- `overflow`: thumbs will not be bound by the track. No extra offset will be added. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `update:modelValue` | `payload: number[][]` | Event handler called when the slider area value changes |
| `valueCommit` | `payload: number[][]` | Event handler called when the value changes at the end of an interaction. |

**Slots**

| Slot | Payload | Description |
| --- | --- | --- |
| `modelValue` | `number[][] \| null` | Current slider area values |

[SliderAreaRoot.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/SliderArea/SliderAreaRoot.vue)

| Data attribute | Value |
| --- | --- |
| `[data-disabled]` | Present when disabled |

### Area

The visual area that represents the 2D range. Must live inside `SliderAreaRoot`. Typically styled with a background color or gradient. Contains the `SliderAreaRegion`.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[SliderAreaArea.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/SliderArea/SliderAreaArea.vue)

| Data attribute | Value |
| --- | --- |
| `[data-disabled]` | Present when disabled |

### Region

The region part. Must live inside `SliderAreaArea`. Represents the bounding box of all thumbs — for a single thumb it spans from the origin to the thumb position, and for multiple thumbs it spans from the minimum to the maximum thumb position on each axis.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"span"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[SliderAreaRegion.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/SliderArea/SliderAreaRegion.vue)

| Data attribute | Value |
| --- | --- |
| `[data-disabled]` | Present when disabled |

### Thumb

A draggable thumb that positions itself within the 2D area. It has `role="slider"` and handles focus and keyboard navigation for both axes. You can render multiple thumbs.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[SliderAreaThumb.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/SliderArea/SliderAreaThumb.vue)

| Data attribute | Value |
| --- | --- |
| `[data-disabled]` | Present when disabled |

## Examples

### Define step size

Use the `stepX` and `stepY` props to increase the stepping interval for each axis.

```vue {9,10}
// index.vue
<script setup>
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar'
</script>

<template>
  <SliderAreaRoot
    :default-value="[[50, 50]]"
    :step-x="10"
    :step-y="10"
  >
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

### Custom axis ranges

Use the `minX`, `maxX`, `minY`, and `maxY` props to define custom ranges for each axis.

```vue {8,9,10,11}
// index.vue
<script setup>
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar'
</script>

<template>
  <SliderAreaRoot
    :min-x="0"
    :max-x="360"
    :min-y="0"
    :max-y="100"
    :default-value="[[180, 50]]"
  >
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

### Multiple thumbs

Add multiple `SliderAreaThumb` components to create a multi-point slider area.

```vue {7,16,17}
// index.vue
<script setup>
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar'
</script>

<template>
  <SliderAreaRoot :default-value="[[25, 25], [75, 75]]">
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

### Prevent thumb overlap

Use `minXStepsBetweenThumbs` and `minYStepsBetweenThumbs` to enforce a minimum distance between thumbs on each axis. Each axis is constrained independently — restricting one axis does not prevent movement on the other.

```vue {10,11}
// index.vue
<script setup>
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar'
</script>

<template>
  <SliderAreaRoot
    :default-value="[[25, 25], [75, 75]]"
    :step-x="10"
    :step-y="10"
    :min-x-steps-between-thumbs="1"
    :min-y-steps-between-thumbs="1"
  >
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

### Inverted axes

Use the `invertedX` and `invertedY` props to invert the direction of each axis.

```vue {9,10}
// index.vue
<script setup>
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar'
</script>

<template>
  <SliderAreaRoot
    :default-value="[[20, 30]]"
    inverted-x
    inverted-y
  >
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

### Thumb alignment

Use the `thumbAlignment` prop to control how the thumb is positioned relative to the track edges.

- `overflow` (default): the thumb can visually overflow the track boundaries.
- `contain`: the thumb is contained within the track boundaries.

```vue {9}
// index.vue
<script setup>
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb } from 'akar'
</script>

<template>
  <SliderAreaRoot
    :default-value="[[50, 50]]"
    thumb-alignment="contain"
  >
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>
    <SliderAreaThumb />
  </SliderAreaRoot>
</template>
```

## Accessibility

Adheres to the [Slider WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/slider).

### Keyboard Interactions

| Key | Description |
| --- | --- |
| <kbd>ArrowRight</kbd> | Increases the X value by the `stepX` amount. |
| <kbd>ArrowLeft</kbd> | Decreases the X value by the `stepX` amount. |
| <kbd>ArrowDown</kbd> | Increases the Y value by the `stepY` amount. SliderArea uses screen-coordinate convention where Y increases downward. Use `invertedY` to flip this. |
| <kbd>ArrowUp</kbd> | Decreases the Y value by the `stepY` amount. SliderArea uses screen-coordinate convention where Y increases downward. Use `invertedY` to flip this. |
| <kbd>Shift + ArrowRight</kbd> | Increases the X value by a larger `stepX`. |
| <kbd>Shift + ArrowLeft</kbd> | Decreases the X value by a larger `stepX`. |
| <kbd>Shift + ArrowDown</kbd> | Increases the Y value by a larger `stepY`. |
| <kbd>Shift + ArrowUp</kbd> | Decreases the Y value by a larger `stepY`. |
| <kbd>Home</kbd> | Sets the X value to its minimum, regardless of `dir` or `invertedX`. |
| <kbd>End</kbd> | Sets the X value to its maximum, regardless of `dir` or `invertedX`. |
| <kbd>PageUp</kbd> | Decreases the Y value by a larger `stepY`. |
| <kbd>PageDown</kbd> | Increases the Y value by a larger `stepY`. |

#### Inverted axes

When axes are inverted, some keyboard controls are inverted as well:

- When `invertedX` is set (or `dir` is `rtl`), `→`, `←`, `Shift + ArrowRight`, and `Shift + ArrowLeft` are inverted.
- When `invertedY` is set, `↑`, `↓`, `PageUp`, `PageDown`, `Shift + ArrowUp`, and `Shift + ArrowDown` are inverted.

## Custom APIs

Create your own API by abstracting the primitive parts into your own component.

### Abstract all parts

This example abstracts all of the `SliderArea` parts so it can be used as a self-closing element.

#### Usage

```vue
<script setup lang="ts">
import { SliderArea } from './your-slider-area';
</script>

<template>
  <SliderArea :default-value="[[50, 50]]" />
</template>
```

#### Implementation

```ts
// your-slider-area.ts
export { default as SliderArea } from './SliderArea.vue';
```

```vue
 <!-- SliderArea.vue -->
<script setup lang="ts">
import type { SliderAreaRootEmits, SliderAreaRootProps } from 'akar';
import { SliderAreaArea, SliderAreaRegion, SliderAreaRoot, SliderAreaThumb, useForwardPropsEmits } from 'akar';

const props = defineProps<SliderAreaRootProps>();
const emits = defineEmits<SliderAreaRootEmits>();

const forward = useForwardPropsEmits(props, emits);
</script>

<template>
  <SliderAreaRoot
    v-slot="{ modelValue }"
    v-bind="forward"
  >
    <SliderAreaArea>
      <SliderAreaRegion />
    </SliderAreaArea>

    <SliderAreaThumb
      v-for="(_, i) in modelValue"
      :key="i"
    />
  </SliderAreaRoot>
</template>
```

## Caveats

### Mouse events are not fired

Because of a limitation in the implementation, the following example won't work as expected and the `@mousedown` and `@mouseup` event handlers won't be fired:

```vue
<SliderAreaRoot
  @mousedown="() => { console.log('onMouseDown')  }"
  @mouseup="() => { console.log('onMouseUp')  }"
>
  …
</SliderAreaRoot>
```

We recommend using pointer events instead (eg. `@pointerdown`, `@pointerup`). Regardless of the above limitation, these events are better suited for cross-platform/device handling as they are fired for all pointer input types (mouse, touch, pen, etc.).

---

- [ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/slider)
- [GitHub](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/SliderArea)
- [npm](https://www.npmjs.com/package/akar)


## Sitemap

See the full [sitemap](https://vinicunca.dev/sitemap.md) for all pages.
