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.

QUIZ

Question 1:Which HTML input type provides a visual tool for selecting a color value?

Question 2:If no default value is specified in a color input, browsers use black (#000000) as the default color.

Question 3:Which of the following are valid use cases for input type="color" in a school web application?

Question 4:What is the format of the value returned from a color input field?

Question 5:Every browser renders the same color picker UI for type="color".

Question 6:Which of the following examples show valid implementation of color input fields?

Mallikarjuna Mallisetty, author
About the author

Mallikarjuna Mallisetty

General programming

Mallikarjuna shares practical programming tutorials and foundational concepts designed to help developers learn by building and experimenting.

View LinkedIn profile ↗