<script setup lang="ts">
import {
ColorAreaArea,
ColorAreaRoot,
ColorAreaThumb,
} from 'akar';
import { ref } from 'vue';
import './styles.css';
const color = ref('#56d799');
</script>
<template>
<div class="akar-demo akar-demo-ColorArea">
<div class="ColorAreaDemo">
<div class="ColorAreaValue">
Current: {{ color }}
</div>
<ColorAreaRoot
v-slot="{ style }"
v-model="color"
class="ColorAreaRoot"
>
<ColorAreaArea
class="ColorAreaArea"
:style="style"
>
<ColorAreaThumb class="ColorAreaThumb" />
</ColorAreaArea>
</ColorAreaRoot>
</div>
</div>
</template>@import '../_colors/black-alpha.css';
@import '../_colors/grass.css';
@import '../_colors/mauve.css';
@scope (.akar-demo-ColorArea) {
.ColorAreaDemo {
display: flex;
flex-direction: column;
gap: 16px;
}
.ColorAreaValue {
color: var(--mauve-11);
font-size: 14px;
}
.ColorAreaRoot {
position: relative;
}
.ColorAreaArea {
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 8px;
}
.ColorAreaArea:focus {
outline: none;
box-shadow: 0 0 0 2px var(--grass-7);
}
.ColorAreaThumb {
display: block;
width: 16px;
height: 16px;
cursor: pointer;
background-color: white;
border: 2px solid var(--mauve-8);
border-radius: 9999px;
box-shadow: 0 2px 10px var(--black-a7);
}
}Features
- Supports HSL, HSB, and RGB color spaces.
- Configurable channels for horizontal (x) and vertical (y) axes.
- Full keyboard navigation support.
- Pointer/touch interaction for value selection.
- Preserves hue information when saturation is 0.
- Form integration with hidden inputs.
Installation
Install the component from your command line.
pnpm add akar
yarn add akar
npm install akar
bun add akar
Anatomy
Import all parts and piece them together.
<script setup>
import {
ColorAreaArea,
ColorAreaRoot,
ColorAreaThumb,
} from 'akar';
</script>
<template>
<ColorAreaRoot v-slot="{ style }">
<ColorAreaArea :style="style">
<ColorAreaThumb />
</ColorAreaArea>
</ColorAreaRoot>
</template>
API Reference
ColorAreaRoot
The root component that provides the color area context and state management.
| Prop | Default | Type |
|---|---|---|
as | "div" | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
colorSpace | "hsl" | "hsl" | "rgb" | "hsb"The color space to operate in. |
defaultValue | "#ff0000" | string | ColorThe default color value (uncontrolled). |
disabled | false | booleanWhen |
modelValue | string | ColorThe color value (controlled). Can be a hex string or Color object. | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
required | booleanWhen | |
xChannel | "hue" | "hue" | "saturation" | "red" | "green" | "blue" | "alpha" | "lightness" | "brightness"Color channel for the horizontal (x) axis. |
xName | stringThe name of the x channel input element for form submission. | |
yChannel | "saturation" | "hue" | "saturation" | "red" | "green" | "blue" | "alpha" | "lightness" | "brightness"Color channel for the vertical (y) axis. |
yName | stringThe name of the y channel input element for form submission. |
| Event | Payload |
|---|---|
change | value: string |
changeEnd | value: string |
update:color | value: Color |
update:modelValue | value: string |
| Slot (default) | Payload |
|---|---|
style | CSSPropertiesCSS styles for the color area background gradient |
ColorAreaArea
The interactive area component where users can select color values by clicking or dragging.
| Prop | Default | Type |
|---|---|---|
as | "div" | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
ColorAreaThumb
The draggable thumb component that indicates the current position in the color area.
| Prop | Default | Type |
|---|---|---|
as | "span" | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
Examples
HSL Saturation/Lightness
A common use case for color area is selecting saturation and lightness in HSL color space.
<script setup>
import {
ColorAreaArea,
ColorAreaRoot,
ColorAreaThumb,
} from 'akar';
import { ref } from 'vue';
const color = ref('#3b82f6');
</script>
<template>
<ColorAreaRoot
v-slot="{ style }"
v-model="color"
color-space="hsl"
x-channel="saturation"
y-channel="lightness"
>
<ColorAreaArea :style="style">
<ColorAreaThumb />
</ColorAreaArea>
</ColorAreaRoot>
</template>
RGB Red/Green Selector
Using RGB color space with red and green channels.
<script setup>
import {
ColorAreaArea,
ColorAreaRoot,
ColorAreaThumb,
} from 'akar';
import { ref } from 'vue';
const color = ref('#ff0000');
</script>
<template>
<ColorAreaRoot
v-slot="{ style }"
v-model="color"
color-space="rgb"
x-channel="red"
y-channel="green"
>
<ColorAreaArea :style="style">
<ColorAreaThumb />
</ColorAreaArea>
</ColorAreaRoot>
</template>
Disabled State
Disable interaction with the color area.
<script setup>
import {
ColorAreaArea,
ColorAreaRoot,
ColorAreaThumb,
} from 'akar';
import { ref } from 'vue';
const color = ref('#3b82f6');
</script>
<template>
<ColorAreaRoot
v-slot="{ style }"
v-model="color"
disabled
>
<ColorAreaArea :style="style">
<ColorAreaThumb />
</ColorAreaArea>
</ColorAreaRoot>
</template>
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
ArrowLeft | Decreases the x-axis channel value by one step. |
ArrowRight | Increases the x-axis channel value by one step. |
ArrowUp | Increases the y-axis channel value by one step. |
ArrowDown | Decreases the y-axis channel value by one step. |
Shift + ArrowKey | Changes values by 10 steps at a time. |
PageUp | Increases the y-axis channel value by a larger step. |
PageDown | Decreases the y-axis channel value by a larger step. |
Home | Jumps left (decreases x-axis value). |
End | Jumps right (increases x-axis value). |