28 CSS Input Fields19 / 28

Pure CSSMIT licensed

Color Picker

A <input type="color"> swatch chip paired with a hex text field — both accept the same `name` and submit value via the underlying form. Sibling-`+` selectors mirror the swatch state.

Published

Live Demo
Try it

The code

<label class="if-19">
  <span class="if-19-label">Brand colour</span>
  <span class="if-19-wrap">
    <input type="color" id="if-19-c" value="#7c6cff" aria-label="Pick colour" />
    <input
      type="text"
      id="if-19-t"
      value="#7c6cff"
      aria-label="Hex value"
      pattern="^#[0-9A-Fa-f]{6}$"
    />
  </span>
</label>
.if-19 {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 280px;
}

.if-19-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #b8b6d4;
  text-transform: uppercase;
}

.if-19-wrap {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  background: #1a1a22;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.if-19-wrap:focus-within {
  border-color: #7c6cff;
}

.if-19 input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 6px;
  border: 0;
  outline: none;
  cursor: pointer;
  background: transparent;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.if-19 input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.if-19 input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.if-19 input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  border: 0;
  outline: none;
  background: transparent;
  color: #f0eeff;
  font: 600 13px/1 "JetBrains Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Input Field from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Color Picker
Source: https://codefronts.com/components/css-input-fields/color-picker/

A <input type="color"> swatch chip paired with a hex text field — both accept the same `name` and submit value via the underlying form. Sibling-`+` selectors mirror the swatch state.
## HTML
```html
<label class="if-19">
  <span class="if-19-label">Brand colour</span>
  <span class="if-19-wrap">
    <input type="color" id="if-19-c" value="#7c6cff" aria-label="Pick colour" />
    <input
      type="text"
      id="if-19-t"
      value="#7c6cff"
      aria-label="Hex value"
      pattern="^#[0-9A-Fa-f]{6}$"
    />
  </span>
</label>
```
## CSS
```css
.if-19 {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 280px;
}

.if-19-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #b8b6d4;
  text-transform: uppercase;
}

.if-19-wrap {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  background: #1a1a22;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.if-19-wrap:focus-within {
  border-color: #7c6cff;
}

.if-19 input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 6px;
  border: 0;
  outline: none;
  cursor: pointer;
  background: transparent;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.if-19 input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.if-19 input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.if-19 input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  border: 0;
  outline: none;
  background: transparent;
  color: #f0eeff;
  font: 600 13px/1 "JetBrains Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
```

How this works

A native input type="color" swatch paired with a hex text field inside a single focus-within shell. The color input returns a lowercase #rrggbb string on change; the text input mirrors it with a pattern attribute so submit-time validation catches malformed hex.

The swatch is sized to 44×44 so the tap target passes WCAG 2.5.5, and ::-webkit-color-swatch is rounded to blend with the wrapper. This is the brand-tool / design-token pattern — a native input type color hex picker for CSS variable panels, theme editors, and pipeline color-token forms without shipping a color-picker library.

Make it yours

  • Change the initial value to any brand hex; the swatch renders it immediately on load.
  • Swap the text input's pattern to accept 3-digit shorthand or 8-digit hex with alpha.
  • Retint the focus-within border to the token you're editing for live feedback.
  • Add a JS input listener to sync the two fields both directions for full round-trip.

Gotchas — read before shipping

  • Chrome caps the native swatch at its intrinsic size — you can't make the popover larger than the OS picker.
  • Safari opens the macOS system color panel and returns #rgb in lowercase; Firefox uses its own dialog.
  • input type="color" can't return alpha or non-hex formats — parse to HSL/RGBA yourself if needed.

Browser support

ChromeSafariFirefoxEdge
20+12.1+29+20+

Native color input is universal; picker UI is the OS/browser, not restylable beyond the swatch pseudo.

Search CodeFronts

Loading…