HTML DOM Input Color Object

The HTML DOM Input Color Object represents an input HTML element with type color.


Following is the syntax −

  • Creating an <input> with type color −
var colorObject = document.createElement(“input”);
colorObject.type = “color”;


Here, “colorObject” can have the following attributes −

autocompleteIt defines the value of autocomplete attribute of a color picker
autofocusIt defines if the color picker should be focused on initial page load.
defaultValueIt sets/returns the default value of color picker
disabledIt defines if color picker is disabled/enabled
formIt returns a reference of enclosing form that contains the color picker
nameIt defines the value of name attribute of a color picker
typeIt returns the type of form element of color picker
valueIt defines the value of the value attribute of a color picker


Let us see an example of Input Color name property −

 Live Demo

<!DOCTYPE html>
<title>Input Color Name</title>
<form id="formForColorsInput">
Color Picker: <input type="color" id="Color" name="primaryColor">
<button onclick="changeNameValue()">Change name value</button>
<div id="divDisplay"></div>
   var inputColor = document.getElementById("Color");
   var divDisplay = document.getElementById("divDisplay");
   divDisplay.textContent = 'Name of color input: ';
   function changeNameValue() {
      if( == 'primaryColor'){ = 'secondaryColor';
         divDisplay.textContent = 'Name of color input: ';


This will produce the following output −

Before clicking ‘Change name value’ button −

After clicking ‘Change name value’ button −

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started