<input type='color' value='#f594d0' />

Why A Colorpicker?

I wasn't satisfied with the solutions available for colorpicking. Many of them included a ton of images, were hard to skin or customize, or were very large plugins. Here are the goals I had when making a new one:

Small Footprint

see a working jsFiddle example

Just include the needed CSS and JavaScript files, and you are ready to go!

<script src='spectrum.js'></script>
<link rel='stylesheet' href='spectrum.css' />

We don't need no stinkin' images!

Nobody wants to add a bunch of code into their project. Spectrum is contained in two files, and both are careful not to mess with your existing code. The JavaScript is well less than 10K gzipped, see the current size in the README.


I wanted an option for the most basic use case, a polyfill for the input[type=color] HTML5 control. This mode needs to work without JavaScript enabled - and fallback to an input[type=text] like other HTML5 inputs.


Just because you don't have to change anything to get it to work, doesn't mean you can't! It is easy to skin and customize the plugin with CSS, and there are a wide range of modes and options to explore.

Mobile Support

Along with desktop browser support, I wanted a mobile colorpicker that was touch friendly, worked in iOS and Android, and used standards that maximize future mobile support.


Believe it or not, this colorpicker lives inside of Chrome devtools to make picking colors easier for web developers and designers.

When I started the project, I wrote about developer tools concept colorpicker implementation. After that, I was contacted on the devtools mailing list and got some initial feedback about the possibility of integrating it with devtools. Then I pulled the jQuery dependency out of a branch and I submitted a patch to the WebKit project.

From there, I opened a development case, entitled Web Inspector: Add colorpicker functionality to color swatches in Styles Sidebar. 50+ comments and 10 patches later, the case landed in WebKit. Thanks to all the WebKit developers who helped me along the way with getting the code and UI ready for committing.



If you just want to provide a polyfill for the native color input, the easiest way is to create an input with the type of color. Once a user's browser supports a native color control, it will opt to use their native control instead.

Unlike the other modes, your value must be a 6 character hex value starting with a '#'. Why? Because the spec says so, that's why.

<input type='color' name='color' />
<input type='color' name='color2' value='#3355cc' />

That's it! The field will degrade to a text input if the user does not have JavaScript enabled, so that they will still be able to manually enter a color. You don't need to add a single line of code.


If you want to get more into the functionality, just create a normal input and initialize it as a normal jQuery plugin. You can set a lot of options when initializing the colorpicker. See the 'Options' section below.

<input type='text' id="custom" />
    color: "#f00"


Flat This means that it will always show up at full size, and be positioned as an inline-block element. Look to the left for a full sized flat picker.

<input type='text' id="flat" />
    flat: true,
    showInput: true


    color: tinycolor,
    flat: bool,
    showInput: bool,
    showInitial: bool,
    showAlpha: bool,
    disabled: bool,
    localStorageKey: string,
    showPalette: bool,
    showPaletteOnly: bool,
    showSelectionPalette: bool,
    clickoutFiresChange: bool,
    cancelText: string,
    chooseText: string,
    className: string,
    preferredFormat: string,
    maxSelectionSize: int,
    palette: [[string]],
    selectionPalette: [string]


The initial color will be set with the color option. If you don't pass in a color, Spectrum will use the value attribute on the input.

The color parsing is based on the TinyColor plugin. This should parse any color string you throw at it.

<input type='text' class='basic' value='red' />
<input type='text' class='basic' value='#0f0' />
<input type='text' class='basic' value='blue' />
<br />
<input type='text' class='override' />
    color: "yellow"

Show Input

You can add an input to allow free form typing. The color parsing is very permissive in the allowed strings. See TinyColor for more details.

    showInput: true

Show Alpha

You can allow alpha transparency selection. Check out these examples:

    showAlpha: true


Spectrum can be automatically disabled if you pass in the disabled flag. Additionally, if the input that you initialize spectrum on is disabled, this will be the default value. Note: you cannot enable spectrum if the input is disabled (see below).

    disabled: true


Show Palette

Spectrum can show a palette below the colorpicker to make it convenient for users to choose from frequently or recently used colors. When the colorpicker is closed, the current color will be added to the palette if it isn't there already. Check it out here:

    showPalette: true,
    palette: [
        ['black', 'white', 'blanchedalmond'],
        ['rgb(255, 128, 0);', 'hsv 100 70 50', 'lightyellow']

Show Palette Only

see a working jsFiddle example

If you'd like, spectrum can show the palettes you specify, and nothing else.

    showPaletteOnly: true,
    color: 'blanchedalmond',
    palette: [
        ['black', 'white', 'blanchedalmond',
        'rgb(255, 128, 0);', 'hsv 100 70 50'],
        ['red', 'yellow', 'green', 'blue', 'violet']

Show Selection Palette

Spectrum can keep track of what has been selected by the user with the showSelectionPalette option.

If the localStorageKey option is defined, the selection will be saved in the browser's localStorage object

    showPalette: true,
    showSelectionPalette: true, // true by default
    palette: [ ]
    showPalette: true,
    showSelectionPalette: true,
    palette: [ ],
    localStorageKey: "spectrum.homepage", // Any Spectrum with the same string will share selection
This colorpicker will store what you pick:

Try reloading your page, it will still be here on this one:

Clickout Fires Change

When clicking outside of the colorpicker, you can force it to fire a change event rather than having it revert the change.

    clickoutFiresChange: true


Show Initial

Spectrum can show the color that was initially set when opening. This provides an easy way to click back to what was set when opened.

    showInitial: true

Show Input and Initial

If you specify both the showInput and showInitial options, the CSS keeps things in order by wrapping the buttons to the bottom row, and shrinking the input. Note: this is all customizable via CSS.

    showInitial: true,
    showInput: true

Button Text

You can set the button's text using cancelText and chooseText properties.

    chooseText: "Alright",
    cancelText: "No way"

Show Buttons

You can show or hide the buttons using the showButtons property. If there are no buttons, the behavior will be to fire the `change` event (and update the original input) when the picker is closed.

    showButtons: false

Preferred Format

You can set the format that is displayed

    preferredFormat: "hex",
    showInput: true
    preferredFormat: "hex6",
    showInput: true
    preferredFormat: "hsl",
    showInput: true
    preferredFormat: "rgb",
    showInput: true
    preferredFormat: "name",
    showInput: true
    showInput: true
Hex (6 Characters Always)
Name (Falls back to hex)
None (Depends on input - try changing formats with the text box)


    move: function(tinycolor) { },
    show: function(tinycolor) { },
    hide: function(tinycolor) { },
    beforeShow: function(tinycolor) { },


Called as the original input changes. Only happens when the input is closed or the 'Choose' button is clicked.

change: function(color) {
    color.toHexString(); // #ff0000


Called as the user moves around within the colorpicker

move: function(color) {
    color.toHexString(); // #ff0000


Called after the colorpicker is hidden. This happens when clicking outside of the picker while it is open. Note, when any colorpicker on the page is shown it will hide any that are already open. This event is ignored on a flat colorpicker.

            hide: function(color) {
                color.toHexString(); // #ff0000


Called after the colorpicker is opened. This is ignored on a flat colorpicker. Note, when any colorpicker on the page is shown it will hide any that are already open.

            show: function(color) {
                color.toHexString(); // #ff0000


You can prevent the colorpicker from showing up if you return false in the beforeShow event. This event is ignored on a flat colorpicker.

beforeShow: function(color) {
    return false; // Will never show up


$("#picker").spectrum("set", colorString);


Shows the colorpicker.


Hides the colorpicker.


Toggles the colorpicker.


Gets the current value from the colorpicker.


Setting the colorpicker programmatically will update the original input.

Note: this will not fire the change event, to prevent infinite loops from calling set from within change.

<input type='text' value='blanchedalmond' name='triggerSet' id='triggerSet' />
<input type='text' placeholder='Enter A Color' id='enterAColor' />
<button id='btnEnterAColor'>Trigger Set</button>


// Show the original input to demonstrate the value changing when calling `set`

$("#btnEnterAColor").click(function() {
    $("#triggerSet").spectrum("set", $("#enterAColor").val());


Retrieves the container element of the colorpicker, in case you want to manaully position it or do other things.


Resets the positioning of the container element. This could be used if the colorpicker is inside of a moving area.


Removes the colorpicker functionality and restores the element to its original state.


Allows selection of the colorpicker component. If it is already enabled, this method does nothing.

Additionally, this will cause the original (now hidden) input to be set as disabled.


Disables selection of the colorpicker component. Adds the sp-disabled class onto the replacer element. If it is already disabled, this method does nothing.

Additionally, this will remove the disabled property on the original (now hidden).


Since it is all built with HTML/CSS, you can skin it easily. There are two parts to the spectrum.css file, the core rules (at the top of the file), and the themable rules (at the bottom). Feel free to tweak these rules to make it look how you want.

Non-input elements

You can use any element you would like to trigger the colorpicker: Click me to open a colorpicker, though it is strongly recommended to stick with <input> tags.

Nitty Gritty

Browser Support

I wanted this to work in the latest and greatest browsers, but also target backwords compatibility and mobile support. Here are the currently supported browers:

IE Implementation

IE Support is provided using proprietary filters. Other browsers use CSS gradients.

Accepted Color Inputs

Spectrum will use the color passed in to initialize. If there is no color passed in, it will try to parse a color based on the value of the input. The color parsing is based on the TinyColor plugin, and accepts many forms of input:

rgb(255, 0, 0)
rgb 255 0 0
hsl(0, 100, 50)
hsl(0, 100%, 50%)
hsl 0 100 50
hsl 0 100% 50%
hsv(0, 100%, 100%)
hsv(0, 100, 100)
hsv 0 100% 100%
hsv 0 100 100

It also provides the following forms of output:

var t = $("#element").spectrum("get");
t.toHex()       // "ff0000"
t.toHexString() // "#ff0000"
t.toRgb()       // {"r":255,"g":0,"b":0}
t.toRgbString() // "rgb(255, 0, 0)"
t.toHsv()       // {"h":0,"s":1,"v":1}
t.toHsvString() // "hsv(0, 100%, 100%)"
t.toHsl()       // {"h":0,"s":1,"l":0.5}
t.toHslString() // "hsl(0, 100%, 50%)"
t.toName()      // "red"