HTML Color Input Generator
WM-52Describe the field on a few lines and get a labelled input of type color, with an optional list of preset colours.
Runs in your browser. Nothing is uploaded.
Attribute lines: label:, name:, id:, value:, colors:, hint:
HTML
How to use it
- Write label:, and optionally name:, id: and hint: lines.
- Add value: with a hex colour such as #ff8800 to set the starting colour.
- Add colors: with comma-separated hex values to create a datalist of presets.
- Pick label style, wrapper and indent, then copy the HTML.
How a color input stores its value
An input of type color always holds a colour in the seven-character form #rrggbb, using lowercase hex digits. If the value is missing or not in that form, the browser falls back to #000000, which is black. This is why the generator rewrites a short value such as #F80 to #ff8800 and refuses anything else, such as a colour name or rgb(). The page script reads the chosen colour from the input's value property as that same string.
Events and what the form sends
A form submits the colour as name=%23ff8800, with the hash sign percent-encoded. In script, the input event fires while the user moves through the picker, and the change event fires when the picker is closed or the choice is committed. Use input for a live preview and change when you only need the final pick. The picker is drawn by the browser, so its look differs between systems and you cannot style its inside.
Preset swatches with a datalist
The colors line creates a datalist and links it to the input with the list attribute. Whether and how a browser offers those presets in its colour picker varies, so test in the browsers you support and treat the presets as a convenience, not a guarantee. The generated input sets no alpha channel, so transparent colours are not expressed. A hint line is linked to the input with aria-describedby.
Questions people ask
What format does input type=color use?
The value is #rrggbb in lowercase hex, such as #ff8800. Any other string is replaced by #000000 by the browser. The tool normalises short hex like #f80 and rejects other formats.
What is the default colour of a color input?
Black, #000000, when no value is given. Set a value line if you want a different starting colour. This tool leaves the value out unless you add a value line, so the browser applies that default itself.
How do I get the selected colour in JavaScript?
Read input.value, which is the #rrggbb string. Listen to the input event for live updates while the picker is open, or the change event for the final choice.
Can a color input have preset colours?
You can attach a datalist with the list attribute, and this tool writes one from the colors line. Browser support for showing those presets differs, so check your target browsers.
Can I style the colour picker itself?
Not the popup. The browser draws it. You can style the small swatch button with CSS, but the dialog stays as the operating system or browser shows it.
About this tool
Builds a label plus an input of type color. The value line must be a hex colour such as #ff8800 or the short form #f80; it is written in lowercase six-digit form, which is the only format a color input accepts. Without a value line the browser uses #000000. A colors line (comma separated hex values) adds a datalist linked through the list attribute; how a browser shows those presets in its picker varies, so test it in the browsers you support. The generated input sets no alpha channel. The hint line is linked with aria-describedby. Values are escaped.