- 1HTML Forms
- 2HTML form Tag
- 3HTML Input Types
- 4HTML Labels and Placeholders
- 5HTML Select Dropdown
- 6HTML Checkbox
- 7HTML Radio Buttons
- 8HTML Textarea
- 9HTML Submit and Reset Buttons
- 10HTML Form Validation
- 11HTML Required Fields
- 12HTML Input Pattern Attribute
- 13HTML min and max Attribute
- 14HTML Form Action and Method
- 15HTML Fieldset and Legend
- 16HTML Form Advanced Controls
- 17HTML Date Picker
- 18HTML Range Slider
- 19HTML Color Picker
- 20HTML File Upload
- 21HTML Datalist
- 22HTML Autofocus and Autocomplete
Color Picker in HTML Forms
input type='color'
Color Picker in HTML Forms: Let Users Choose Their Hue
Sometimes a choice needs to be more visual than textual — and that's exactly what <input type="color">
delivers. The HTML color picker lets users select a shade from a full spectrum, and it works natively in modern browsers.
What is type="color"
?
<input type="color">
provides a color selection dialog, usually with a color box that opens a palette. The selected value is stored as a hex code (e.g., #ff0000
for red).
Basic Syntax
<label for="color">Pick a color:</label><br>
<input type="color" id="color" name="colorChoice">
Pick a color: [ 🎨 ]
Clicking the color box opens a color picker interface provided by the browser — no scripting required.
Setting a Default Color
Use the value
attribute to define an initial color. It must be a valid hex code.
<input type="color" name="highlightColor" value="#ffcc00">
[ Default set to a warm yellow ]
If omitted, the default is usually black (#000000
), but this can vary by browser.
Using with Labels and Context
For a better user experience, explain what the color picker is selecting.
<label for="fruitColor">Color that reminds you of banana:</label><br>
<input type="color" id="fruitColor" name="bananaColor" value="#f4e842">
Color that reminds you of banana: [ 🍌 yellowish tone ]
Use Cases for Color Picker
- Theme or UI customization (e.g., user selects background color)
- Design tools (e.g., logo or palette generator)
- Personal preferences (e.g., “what color do you associate with cherry?”)
- Games and creative apps for picking colors dynamically
Full Example: Fruit Palette Survey
<form action="/submit-colors" method="post">
<label for="appleColor">Apple Color:</label><br>
<input type="color" id="appleColor" name="appleColor" value="#d10000"><br><br>
<label for="bananaColor">Banana Color:</label><br>
<input type="color" id="bananaColor" name="bananaColor" value="#f4e842"><br><br>
<label for="cherryColor">Cherry Color:</label><br>
<input type="color" id="cherryColor" name="cherryColor" value="#b3003b"><br><br>
<input type="submit" value="Submit Palette">
</form>
Apple Color: [ 🔴 ]
Banana Color: [ 🟡 ]
Cherry Color: [ 🍒 ]
[Submit Palette]
This form captures a personalized color palette associated with each fruit. The data is submitted as hex codes, such as #d10000
.
Best Practices
- Always use valid hex values for
value
- Pair with meaningful
<label>
s so users know what the color represents - Fallback gracefully — if color input isn't supported, a text input will be shown
Browser Support
Supported in all major modern browsers (Chrome, Edge, Safari, Opera). Firefox and some older browsers may render a basic input field without a UI.
Summary
The HTML color picker simplifies color selection through a visual UI. You've learned how to:
- Use
<input type="color">
- Set default colors using hex values
- Implement real-world use cases like theme design or feedback forms
What’s Next?
Let’s move on to letting users upload files — images, documents, or anything else — using the <input type="file">
control.