HTML DOM Input Color Object

Color Object

The Color Object is a new object in HTML5.

The Color Object represents the HTML <input type="color"> element.

Note:Internet Explorer and Safari do not support the <input type="color"> element.

Access Color Object

You can access the <color> element by using getElementById():

var x = document.getElementById("myColor");

Try it yourself

Tip:You can also iterate over the form's elements collectionto access the Color Object.

Create Color Object

You can create a <color> element by using the document.createElement() method:

var x = document.createElement("INPUT");
x.setAttribute("type", "color");

Try it yourself

Color Object properties

Attribute Description
autocomplete Set or return the autocomplete attribute value of the color picker.
autofocus Set or return whether the color picker should automatically focus after the page is loaded.
defaultValue Set or return the default value of the color picker.
disabled Set or return whether the color picker is disabled.
form Return a reference to the form containing the color picker.
list Return a reference to the datalist containing the color picker.
name Set or return the name attribute value of the color picker.
type Return the form element type of the color picker.
value Set or return the value of the color picker's value attribute.

Standard attributes and events

Color Object supports standardsAttributeandEvent.

Related pages

HTML Tutorial:HTML Form

HTML Reference Manual:HTML <input> tag

HTML Reference Manual:HTML <input> type attribute