|$ curl https://forge-ai.dev/api/markdown?path=docs/components/color-picker
$cat docs/color-picker.md
updated Recently·14 min read·published

Color Picker

CSSHTMLUIAdvanced🎯Free Tools

Color selection components from the native <input type="color"> to custom swatch grids, HSL-based pickers, hex/rgb input fields, and gradient generators \u2014 all with live previews.

Native Color Input

The native <input type="color"> opens the browser's built-in color picker. It returns a hex value and provides a simple, accessible way to select colors with zero JavaScript. The value is always in #RRGGBB format.

native-color
Live
untitled.html
HTML
1<div class="native-demo">
2 <div class="nd-field">
3 <label for="color-native">
4 Pick a color
5 </label>
6 <div class="nd-row">
7 <input type="color" id="color-native" value="#00FF41" class="color-input"/>
8 <span class="nd-value" id="nd-val">
9 #00FF41
10 </span>
11 </div>
12 </div>
13</div>
preview
Native Color Input Styling

The native color input exposes pseudo-elements for customizing the swatch appearance. Use ::-webkit-color-swatch-wrapper for padding and ::-webkit-color-swatch for the color preview itself.

color-input-styling.css
CSS
1/* Remove default padding */
2.color-input::-webkit-color-swatch-wrapper {
3 padding: 0;
4}
5
6/* Style the color swatch */
7.color-input::-webkit-color-swatch {
8 border: none;
9 border-radius: 6px;
10}
11
12/* Firefox uses different pseudo-elements */
13.color-input::-moz-color-swatch {
14 border: none;
15 border-radius: 6px;
16}
17
18/* Container styling */
19.color-input {
20 width: 48px;
21 height: 36px;
22 border: 2px solid #2A2A3E;
23 border-radius: 8px;
24 cursor: pointer;
25 background: transparent;
26 padding: 2px;
27}
Color Swatches

A grid of preset color swatches for quick selection. Clicking a swatch selects it and highlights the active choice with a ring. Ideal for theme pickers, design tools, and branded interfaces where the color palette is curated.

swatches
Live
untitled.html
HTML
1<div class="swatch-demo">
2 <div class="sd-header">
3 <span class="sd-title">
4 Theme Color
5 </span>
6 <span class="sd-hex" id="sd-hex">
7 #00FF41
8 </span>
9 </div>
10 <div class="swatch-grid" id="swatch-grid">
11 <button class="swatch active" data-color="#00FF41" style="background:#00FF41" aria-label="Green">
12 </button>
13 <button class="swatch" data-color="#3B82F6" style="background:#3B82F6" aria-label="Blue">
14 </button>
15 <button class="swatch" data-color="#EF4444" style="background:#EF4444" aria-label="Red">
16 </button>
17 <button class="swatch" data-color="#F59E0B" style="background:#F59E0B" aria-label="Amber">
18 </button>
19 <button class="swatch" data-color="#8B5CF6" style="background:#8B5CF6" aria-label="Purple">
20 </button>
21 <button class="swatch" data-color="#EC4899" style="background:#EC4899" aria-label="Pink">
22 </button>
23 <button class="swatch" data-color="#14B8A6" style="background:#14B8A6" aria-label="Teal">
24 </button>
25 <button class="swatch" data-color="#F97316" style="background:#F97316" aria-label="Orange">
26 </button>
27 <button class="swatch" data-color="#E0E0E0" style="background:#E0E0E0" aria-label="Light">
28 </button>
29 <button class="swatch" data-color="#808080" style="background:#808080" aria-label="Gray">
30 </button>
31 <button class="swatch" data-color="#444444" style="background:#444444" aria-label="Dark">
32 </button>
33 <button class="swatch" data-color="#000000" style="background:#000000;border:1px solid #333" aria-label="Black">
34 </button>
35 </div>
36</div>
preview
Hex & RGB Inputs

Manual color entry with hex and RGB input fields. Changes in any field update all others and the live preview swatch. Supports both #RRGGBB and shorthand #RGB formats. The RGB inputs clamp values to 0-255.

hex-rgb
Live
untitled.html
HTML
1<div class="hex-rgb-demo">
2 <div class="hr-preview" id="hr-preview" style="background:#00FF41">
3 </div>
4 <div class="hr-fields">
5 <div class="hr-group">
6 <label>
7 HEX
8 </label>
9 <input type="text" class="hr-input hex" id="hr-hex" value="#00FF41" maxlength="7"/>
10 </div>
11 <div class="hr-group">
12 <label>
13 R
14 </label>
15 <input type="number" class="hr-input rgb" id="hr-r" min="0" max="255" value="0"/>
16 </div>
17 <div class="hr-group">
18 <label>
19 G
20 </label>
21 <input type="number" class="hr-input rgb" id="hr-g" min="0" max="255" value="255"/>
22 </div>
23 <div class="hr-group">
24 <label>
25 B
26 </label>
27 <input type="number" class="hr-input rgb" id="hr-b" min="0" max="255" value="65"/>
28 </div>
29 </div>
30 <div class="hr-output">
31 <span class="hr-label">
32 CSS:
33 </span>
34 <code id="hr-css">
35 rgb(0, 255, 65)
36 </code>
37 </div>
38</div>
preview
HSL Picker

An HSL-based color picker with hue, saturation, and lightness sliders. HSL is more intuitive for designers \u2014 adjusting hue rotates around the color wheel, while saturation and lightness control intensity and brightness. Each slider's track gradient updates dynamically.

hsl-picker
Live
untitled.html
HTML
1<div class="hsl-demo">
2 <div class="hsl-preview" id="hsl-preview" style="background:hsl(140,100%,50%)">
3 </div>
4 <div class="hsl-fields">
5 <div class="hsl-group">
6 <div class="hsl-header">
7 <label>
8 Hue
9 </label>
10 <span class="hsl-val" id="hsl-h-val">
11 140°
12 </span>
13 </div>
14 <input type="range" class="hsl-slider hue" id="hsl-h" min="0" max="360" value="140"/>
15 </div>
16 <div class="hsl-group">
17 <div class="hsl-header">
18 <label>
19 Saturation
20 </label>
21 <span class="hsl-val" id="hsl-s-val">
22 100%
23 </span>
24 </div>
25 <input type="range" class="hsl-slider sat" id="hsl-s" min="0" max="100" value="100"/>
26 </div>
27 <div class="hsl-group">
28 <div class="hsl-header">
29 <label>
30 Lightness
31 </label>
32 <span class="hsl-val" id="hsl-l-val">
33 50%
34 </span>
35 </div>
36 <input type="range" class="hsl-slider light" id="hsl-l" min="0" max="100" value="50"/>
37 </div>
38 </div>
39 <div class="hsl-output">
40 <code id="hsl-css">
41 hsl(140, 100%, 50%)
42 </code>
43 <button class="hsl-copy" id="hsl-copy">
44 Copy
45 </button>
46 </div>
47</div>
preview
Palette Generator

A base color input that generates a 5-shade palette by adjusting lightness. Each shade shows its hex value and can be copied with a click \u2014 useful for design systems, theme configuration, and creating color scales from a brand color.

palette
Live
untitled.html
HTML
1<div class="palette-demo">
2 <div class="pd-input">
3 <label>
4 Base Color
5 </label>
6 <input type="color" value="#3B82F6" id="pal-color" class="pd-picker"/>
7 </div>
8 <div class="pd-shades" id="pd-shades">
9 <div class="pd-shade" style="background:hsl(217,91%,60%)">
10 <span class="pd-label">
11 500
12 </span>
13 <span class="pd-hex">
14 #3B82F6
15 </span>
16 </div>
17 <div class="pd-shade" style="background:hsl(217,91%,40%)">
18 <span class="pd-label">
19 600
20 </span>
21 <span class="pd-hex">
22 #2563EB
23 </span>
24 </div>
25 <div class="pd-shade" style="background:hsl(217,91%,30%)">
26 <span class="pd-label">
27 700
28 </span>
29 <span class="pd-hex">
30 #1D4ED8
31 </span>
32 </div>
33 <div class="pd-shade" style="background:hsl(217,91%,70%)">
34 <span class="pd-label">
35 400
36 </span>
37 <span class="pd-hex">
38 #60A5FA
39 </span>
40 </div>
41 <div class="pd-shade" style="background:hsl(217,91%,85%)">
42 <span class="pd-label">
43 200
44 </span>
45 <span class="pd-hex">
46 #BFDBFE
47 </span>
48 </div>
49 </div>
50</div>
preview
Gradient Picker

A gradient builder with two color stops and angle control. The preview shows the live CSS gradient, and the output displays the ready-to-use linear-gradient() CSS value. Drag the angle slider to rotate the gradient direction.

gradient-picker
Live
untitled.html
HTML
1<div class="grad-demo">
2 <div class="grad-preview" id="grad-preview" style="background:linear-gradient(135deg,#3B82F6,#8B5CF6)">
3 </div>
4 <div class="grad-fields">
5 <div class="grad-row">
6 <label>
7 Start
8 </label>
9 <input type="color" value="#3B82F6" id="grad-start" class="grad-color"/>
10 <span class="grad-hex" id="grad-start-hex">
11 #3B82F6
12 </span>
13 </div>
14 <div class="grad-row">
15 <label>
16 End
17 </label>
18 <input type="color" value="#8B5CF6" id="grad-end" class="grad-color"/>
19 <span class="grad-hex" id="grad-end-hex">
20 #8B5CF6
21 </span>
22 </div>
23 <div class="grad-row full">
24 <div class="grad-angle-header">
25 <label>
26 Angle
27 </label>
28 <span class="grad-angle-val" id="grad-angle-val">
29 135°
30 </span>
31 </div>
32 <input type="range" class="grad-slider" id="grad-angle" min="0" max="360" value="135"/>
33 </div>
34 </div>
35 <div class="grad-output">
36 <code id="grad-css">
37 linear-gradient(135deg, #3B82F6, #8B5CF6)
38 </code>
39 <button class="grad-copy" id="grad-copy">
40 Copy
41 </button>
42 </div>
43</div>
preview
HTML Structure

The color picker pairs a hidden <input type="color"> with visible hex/RGB inputs and a preview swatch. Sync all inputs bidirectionally so changes in any field update the rest. Include a "Copy CSS" button for convenience.

color-picker-structure.html
HTML
1<div class="color-picker">
2 <!-- Live preview swatch -->
3 <div class="preview-swatch"
4 style="background: #3B82F6"></div>
5
6 <!-- Native color input (hidden label) -->
7 <input type="color" value="#3B82F6"
8 aria-label="Color selector" />
9
10 <!-- Manual hex input -->
11 <label for="hex-input">HEX</label>
12 <input type="text" id="hex-input"
13 value="#3B82F6" maxlength="7" />
14
15 <!-- RGB inputs -->
16 <label for="rgb-r">R</label>
17 <input type="number" id="rgb-r" min="0" max="255" />
18
19 <!-- CSS output -->
20 <code>rgb(59, 130, 246)</code>
21</div>
Best Practices

info

Support multiple color formats (hex, RGB, HSL) and keep them synchronized. Different users think in different formats \u2014 designers often prefer HSL, developers prefer hex, and CSS authors prefer rgb() or hsl().

warning

Always validate hex input before parsing \u2014 accept both #RRGGBB and #RGB shorthand, but reject invalid characters. Use parseInt(value, 16) with error handling to prevent NaN values.

best practice

Include a "Copy CSS" button that copies the color in the most useful format for the context \u2014 hsl() for design tokens, hex for configuration files, rgb for inline styles.
  • Ensure sufficient contrast between the selected color and the preview text \u2014 use white text on dark colors and dark text on light colors dynamically.
  • For swatch grids, always include a neutral/black swatch \u2014 users frequently need to select non-color or default options.
  • Use aria-label on color swatch buttons since color alone is not accessible to screen readers.
  • Consider generating analogous, complementary, and triadic palettes from the selected base color for design exploration.
  • Debounce rapid color changes when syncing with external previews to avoid layout thrashing and excessive re-renders.