HTML Color Input: Color Values and Pickers
Choose a color
Use type="color" when the user needs to choose a color. An opaque six-digit hexadecimal sRGB value is a portable initial choice. The control usually opens a native picker; the appearance is browser-dependent.
<label> Accent color <input type="color" name="accent" value="#2463eb"></label>The initial color is blue. Choose another color in the picker.
Two independent choices
Each named color input contributes its own value when the form is submitted. Give each control a meaningful label. A color alone may be insufficient for a user who cannot distinguish shades.
<form> <label> Background <input type="color" name="background" value="#ffffff"> </label> <label> Text <input type="color" name="foreground" value="#000000"> </label></form>The form contains two independent color values; it does not calculate contrast.
Newer color options
The standard includes alpha for transparency and colorspace="display-p3" for wider-gamut color handling. Implementation varies, including accepted syntax and serialization. Use a conventional initial color and check the specific feature before relying on the enhanced UI.
<label> Theme color <input type="color" value="#336699" alpha colorspace="display-p3"></label>The markup requests alpha and Display P3; unsupported browsers may show a conventional picker.
Common mistakes and practice
Do not promise a particular picker or the exact serialized format for modern color spaces. For an application that generates styles, validate the submitted color against the expected format. Use text descriptions or other indicators alongside color.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Color Input: Color Values and Pickers — Knowledge Check
Apply the control concepts taught in this lesson.
Which initial value is a portable opaque sRGB example?
Which attribute requests transparency support?
How should you describe a chosen color accessibly?
Which attribute identifies the submitted key of a color control?
What should you do before making alpha or Display P3 essential?