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

Color Picker

◆CSS◆HTML◆Tailwind◆Bootstrap◆UI◆Advanced🎯Free Tools
Introduction

Color pickers let users select, explore, and copy color values. This guide covers production-ready patterns in plain HTML/CSS, Tailwind CSS, and Bootstrap — from the native <input type="color"> to custom swatch grids, HSL sliders, palette generators, and gradient builders.

ℹ

info

Always pair custom color pickers with the native input as a fallback. Provide both visual preview and textual value so the selection is accessible and copy-friendly.
Native Color Input

The native <input type="color"> opens the browser's built-in color picker, returns a hex value, and works with zero JavaScript. Use pseudo-elements to style the swatch.

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
Color Swatches

A preset grid of color swatches for quick selection. The active choice is highlighted with a ring. Ideal for theme pickers and curated palettes.

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
Swatch Sizes

Compact, default, and large swatch sizes adapt the same color grid to different contexts — form sidebars, toolbars, and full-width theme panels.

swatch-sizes
Live
untitled.html
HTML
1<div class="size-demo">
2 <div class="size-row">
3 <span class="size-label">
4 Small
5 </span>
6 <div class="size-grid small">
7 <button class="swatch" style="background:#00FF41" aria-label="Green">
8 </button>
9 <button class="swatch" style="background:#3B82F6" aria-label="Blue">
10 </button>
11 <button class="swatch" style="background:#EF4444" aria-label="Red">
12 </button>
13 <button class="swatch" style="background:#F59E0B" aria-label="Amber">
14 </button>
15 </div>
16 </div>
17 <div class="size-row">
18 <span class="size-label">
19 Default
20 </span>
21 <div class="size-grid">
22 <button class="swatch" style="background:#00FF41" aria-label="Green">
23 </button>
24 <button class="swatch" style="background:#3B82F6" aria-label="Blue">
25 </button>
26 <button class="swatch" style="background:#EF4444" aria-label="Red">
27 </button>
28 <button class="swatch" style="background:#F59E0B" aria-label="Amber">
29 </button>
30 </div>
31 </div>
32 <div class="size-row">
33 <span class="size-label">
34 Large
35 </span>
36 <div class="size-grid large">
37 <button class="swatch" style="background:#00FF41" aria-label="Green">
38 </button>
39 <button class="swatch" style="background:#3B82F6" aria-label="Blue">
40 </button>
41 <button class="swatch" style="background:#EF4444" aria-label="Red">
42 </button>
43 <button class="swatch" style="background:#F59E0B" aria-label="Amber">
44 </button>
45 </div>
46 </div>
47</div>
preview
Hex & RGB Inputs

Manual color entry with hex and RGB fields. Changes in any field update all others and the live preview. Supports #RRGGBB and shorthand #RGB formats.

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 picker with hue, saturation, and lightness sliders. Each track gradient updates dynamically as the hue changes.

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. Click any shade to copy its hex value.

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 is ready to copy.

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
Color Harmonies

Generate complementary and triadic color schemes from a single base color. Useful for building balanced palettes and exploring relationships on the color wheel.

harmonies
Live
untitled.html
HTML
1<div class="harmony-demo">
2 <div class="hm-input">
3 <label>
4 Base
5 </label>
6 <input type="color" value="#00FF41" id="hm-base" class="hm-picker"/>
7 </div>
8 <div class="hm-row">
9 <span class="hm-name">
10 Complementary
11 </span>
12 <div class="hm-swatches" id="hm-comp">
13 <div class="hm-swatch" style="background:#00FF41" data-hex="#00FF41">
14 </div>
15 <div class="hm-swatch" style="background:#FF00BE" data-hex="#FF00BE">
16 </div>
17 </div>
18 </div>
19 <div class="hm-row">
20 <span class="hm-name">
21 Triadic
22 </span>
23 <div class="hm-swatches" id="hm-triad">
24 <div class="hm-swatch" style="background:#00FF41" data-hex="#00FF41">
25 </div>
26 <div class="hm-swatch" style="background:#4100FF" data-hex="#4100FF">
27 </div>
28 <div class="hm-swatch" style="background:#FF4100" data-hex="#FF4100">
29 </div>
30 </div>
31 </div>
32</div>
preview
HTML Structure

Pair a native color input with visible hex/RGB inputs and a preview swatch. Sync all inputs bidirectionally and include a copy button.

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 -->
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>
Accessibility

Color pickers must communicate color values to all users, not just sighted ones. Pair visual controls with text labels, keyboard support, and clear focus states.

  • Use a real <input type="color"> as the underlying control so keyboard and screen-reader users can access the browser picker.
  • Add aria-label to every color swatch button — color alone is not accessible.
  • Show the current value as text (hex, RGB, or HSL) next to the preview so it can be read by a screen reader.
  • Ensure focus indicators are visible on sliders, inputs, and swatches.
  • Validate hex input and announce errors if the user enters an invalid format.
  • Copy-to-clipboard buttons should provide visual and textual feedback (for example, "Copied" text).
Best Practices
ℹ

info

Support multiple color formats (hex, RGB, HSL) and keep them synchronized. Designers often prefer HSL, developers prefer hex, and CSS authors prefer rgb() or hsl().
⚠

warning

Always validate hex input before parsing. Accept #RRGGBB and #RGB shorthand, but reject invalid characters to prevent NaN values.
✓

best practice

Include a "Copy CSS" button that copies the color in the most useful format for the context — hsl() for design tokens, hex for configuration files, rgb for inline styles.
  • Ensure sufficient contrast between the selected color and the preview text.
  • For swatch grids, always include a neutral or black swatch for non-color defaults.
  • Debounce rapid color changes when syncing with external previews to avoid layout thrashing.
  • Persist the last selected color in local storage so users do not lose their choice on reload.

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.