Input Color value attribute

Definition and usage

value Attribute sets or returns the value of the value attribute of the color selector.

The HTML value attribute specifies the color of the color selector.

Comment:If nothing is specified, the default color is #000000 (black).

Related pages

HTML Tutorial:Цвета HTML

HTML Reference Manual:Атрибут value элемента <input> HTML

Instance

Example 1

Change the color of the color selector:

document.getElementById("myColor").value = "#FF8040";

Try it yourself

Example 2

Get the color of the color selector:

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

Try it yourself

Example 3

An example showing the difference between the defaultValue and value attributes:

var x = document.getElementById("myColor");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try it yourself

Syntax

Return the value attribute:

colorObject.value

Set the value attribute:

colorObject.value = #hexvalue

Attribute value

Value Description
#hexvalue

Specify the color of the color selector.

This value must be a hexadecimal (hex) value: 3 two-digit numbers, starting with the # symbol (such as #FF8040).

Внимание:Color keywords (such as "red" or "blue") are not allowed.

Comment:Default color is #000000 (black).

Технические детали

Возвратное значение: Строковое значение, представляющее цвет.

Поддержка браузеров

Числа в таблице указывают на версию первого браузера, который полностью поддерживает этот атрибут.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Поддержка 10.0 Поддержка Поддержка Поддержка

Внимание:Элемент <input type="color"> не отображает ни одного выбора цвета в Internet Explorer и Safari.