Color picker

색상 선택기

A control for picking one color from a palette or wheel, built as a swatch grid or handed off to the OS picker.

Also known as: Color swatch pickerSwatch selector
···
html
<div class="cpw">
  <span class="cplabel">강조 색상</span>
  <div class="cpswatches" role="radiogroup" aria-label="색상 선택" id="cpsw">
    <button role="radio" aria-checked="true" aria-label="보라" style="background:#5b5bf7"></button>
    <button role="radio" aria-checked="false" aria-label="핑크" style="background:#f25c8a"></button>
    <button role="radio" aria-checked="false" aria-label="민트" style="background:#18c29c"></button>
    <button role="radio" aria-checked="false" aria-label="주황" style="background:#f2994a"></button>
    <button class="cpcustom" role="radio" aria-checked="false" aria-label="직접 선택"></button>
  </div>
  <div class="cppreview"><span id="cphex">#5B5BF7</span></div>
</div>
css
.cpw{position:absolute;inset:0;display:grid;place-items:center;gap:12px}
.cplabel{color:var(--muted);font-size:10px}
.cpswatches{display:flex;gap:8px}
.cpswatches button{width:26px;height:26px;border-radius:50%;border:2px solid transparent;cursor:default;padding:0}
.cpswatches button[aria-checked=true]{border-color:var(--fg);box-shadow:0 0 0 2px var(--bg)}
.cpcustom{background:conic-gradient(from 0deg,#f25c8a,#f2994a,#e0d454,#18c29c,#5b5bf7,#a35bf7,#f25c8a) !important}
.cppreview{font-size:11px;font-weight:700;color:var(--fg);letter-spacing:.03em}
js
const btns = [...document.querySelectorAll('#cpsw button')];
const hex = document.getElementById('cphex');
const HEX = { 0: '#5B5BF7', 1: '#F25C8A', 2: '#18C29C', 3: '#F2994A', 4: '#A35BF7' };
function select(i) {
  btns.forEach((b, idx) => b.setAttribute('aria-checked', String(idx === i)));
  hex.textContent = HEX[i];
}
let auto = true, i = 0;
btns.forEach((b, idx) => b.addEventListener('click', () => { auto = false; i = idx; select(i); }));
setInterval(() => { if (!auto) return; i = (i + 1) % btns.length; select(i); }, 1100);

A native <input type="color"> opens the OS's own color picker (palette, eyedropper) on click, so accessibility comes for free with no extra work. To restrict choices to a fixed set — a brand palette, say — a custom swatch grid uses role="radiogroup" with each swatch as role="radio", so only one is selected at a time and arrow keys move between them.

Conveying selection or meaning through color alone leaves colorblind and low-vision users unable to tell swatches apart — the same problem the a11y category's "don't rely on color alone" principle addresses. The selected swatch needs a shape signal too — a ring, a checkmark — independent of its color, and each swatch's aria-label should spell out the color's name ("Purple," "Pink") so a screen reader user knows what they're picking.

If free-form color entry is needed too — typing a hex code, dragging a wheel — a common layout adds a "Custom" swatch next to the palette that opens a larger picker (usually HSL or per-channel sliders) when pressed.