StealThis .dev

Color Picker

HSL color picker with canvas gradient, hue slider, hex/rgb output, and opacity slider.

Open in Lab
canvas vanilla-js
Targets: JS HTML

Code

Color Picker

Full HSL color picker built on <canvas>. Drag the crosshair to pick saturation and lightness, drag the hue slider to change hue, and adjust the opacity slider. Outputs Hex, RGB, and RGBA.

Components

ElementDescription
Canvas gradientWhite→hue horizontal, opaque→black vertical
CrosshairDraggable saturation/lightness picker
Hue slider0–360° hue strip
Opacity slider0–100% alpha
Preview swatchLive color swatch with checkerboard background
OutputsHex, RGB, RGBA text fields

Implementation

The canvas renders two overlapping linearGradient fills: white-to-currentHue (x-axis) and transparent-to-black (y-axis). The crosshair position maps to s and l in HSL space. Hex is computed by converting HSL → RGB → hex string.