Input Month value Attribute

Definition and Usage

value Sets or returns the value of the month field's value attribute.

The HTML value attribute specifies the month and year of the month field.

See also:

HTML Reference Manual:HTML <input> value Attribute

Example

Example 1

Set the month and year of the month field:

document.getElementById("myMonth").value = "2023-06";

Try it yourself

Example 2

Get the month and year of the month field:

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

Try it yourself

Example 3

An example to show the difference between the defaultValue and value attributes:

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

Try it yourself

Syntax

Return the value attribute:

monthObject.value

Set the value attribute:

monthObject.value = YYYY-MM

Attribute value

Value Description
YYYY-MM

Specify the month and year.

Component Description:

  • YYYY - Year (for example, 2023)
  • MM - Month (for example, 06 represents June)

Technical Details

Return Value: A string value representing the month and year of the month field.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support

Note:The <input type="month"> element does not display any date field/calendar in Firefox.