Color Picker


Need to select the perfect hue for your website? An HTML color picker is your essential tool! Easily choose, preview, and get the exact hexadecimal (hex) codes, RGB values, and HSL data for any color. Streamline your design workflow and ensure color consistency across your web projects. Find the ideal shade to enhance your site's aesthetics and user experience with a powerful HTML color picker.

Color Picker (<input type="color">)

The HTML5 <input type="color"> creates a color picker interface, allowing users to select a color visually. This is highly useful for web forms where color input is required, providing a consistent user experience across browsers.

Example 1: Basic Color Picker

<label for="favColor">Choose your favorite color:</label>
<input type="color" id="favColor" name="favoriteColor">

Explanation This code snippet generates a standard color picker. The label provides accessibility, linking the text "Choose your favorite color:" to the input field via the for and id attributes.


Example 2: Default Value Color Picker

<label for="bgColor">Select a background color:</label>
<input type="color" id="bgColor" name="backgroundColor" value="#008000">

Explanation Here, we set a default color (#008000, which is green) using the value attribute. This is helpful for pre-filling forms or suggesting a specific color to the user.


Example 3: Color Picker with a Submit Button

<form onsubmit="alert('Selected Color: ' + document.getElementById('myColor').value)">
  <label for="myColor">Pick a color for your theme:</label>
  <input type="color" id="myColor" name="themeColor">
  <button type="submit">Apply Color</button>
  </form>

Explanation This example shows the color picker within a basic HTML form. When the "Apply Color" button is clicked, a JavaScript alert displays the selected color's hexadecimal value.


Example 4: JavaScript Interaction with Color Picker

<label for="liveColor">Live Color Preview:</label>
<input type="color" id="liveColor" name="liveColorPicker" oninput="document.body.style.backgroundColor = this.value;">

Explanation This code demonstrates dynamic interaction. As the user selects a color, the oninput event immediately changes the body's background color to the chosen value, offering a live preview.


Example 5: Disabling a Color Picker

<label for="disabledColor">Disabled Color Picker:</label>
<input type="color" id="disabledColor" name="unavailableColor" value="#FF0000" disabled>

Explanation The disabled attribute renders the color picker unusable by the user. It still displays a default color if provided by the value attribute, but it cannot be changed.