A modern, highly modular, and headless-friendly color picker component built specifically for Svelte 5.
$state, $derived, $effect).<ColorPicker /> component or build your own UI using the provided compound components.colord for fast and precise color manipulation.Install the library using your favorite package manager:
npm install svelte-simple-color-picker
Note:
This library includes default styling using Tailwind CSS. Make sure your project already has Tailwind configured.
The easiest way to use the library is with the main <ColorPicker /> component.
<script lang="ts">
import { ColorPicker } from 'svelte-simple-color-picker';
// Svelte 5 reactive state
let myColor = $state('#3b82f6');
</script>
<div class="w-64 p-4">
<ColorPicker value={myColor} showAlpha={true} onChange={(newColor) => (myColor = newColor)} />
<p class="mt-4">Selected color: {myColor}</p>
</div>
If you are building a highly customized UI (such as a design editor, website builder, or custom design system), you can compose your own color picker using the provided sub-components.
<script lang="ts">
import { setContext } from 'svelte';
import {
ColorStore,
SaturationArea,
HueSlider,
AlphaSlider,
ColorInput
} from 'svelte-simple-color-picker';
// 1. Initialize the ColorStore as the main state manager
const colorStore = new ColorStore('#ff0000');
// 2. Provide it via context so child components can access it
setContext('COLOR_CTX', colorStore);
</script>
<div class="flex max-w-sm flex-col gap-4">
<SaturationArea />
<div class="flex items-center gap-2">
<div class="flex flex-1 flex-col gap-2">
<HueSlider />
<AlphaSlider />
</div>
<div
class="h-10 w-10 rounded-full shadow-inner"
style="background-color: {colorStore.hex};"
></div>
</div>
<ColorInput />
</div>
<ColorPicker /> Props| Prop | Type | Default | Description |
|---|---|---|---|
value |
string |
"#ffffff" |
Initial HEX color value (supports 6 or 8 digit hex including alpha). |
onChange |
(hex: string) => void |
undefined |
Callback triggered whenever the color changes. |
showAlpha |
boolean |
true |
If false, the opacity/alpha slider will be hidden. |
The library exports the following components and utilities:
ColorPicker — Main ready-to-use componentSaturationArea — Saturation and value selection areaHueSlider — Hue selection sliderAlphaSlider — Opacity/alpha sliderColorInput — Manual HEX color inputColorStore — State manager built with $stateContributions are always welcome!
If you find a bug or want to suggest a new feature:
All contributions are appreciated.
MIT License © 2026