HTML <input> Tag with 'type=month'
<form name="myForm" action="http://www.htmlcodes.ws/resources/html-forms-action.cfm">
<input type="month" name="myMonthField">
<button>Submit</button>
</form>
The above example demonstrates usage of the <input>
element with the type
attribute set to month
(i.e. type="month"
).
The month
value represents a control for setting the element's value to a string representing a specific month. This is a date consisting of a year and a month with no time zone.
Specifying a min
and/or max
Date
The min
and max
attributes can be used with the month field to specify a minimum and maximum month. If specified, they must have a value that is a valid month string.
The following example specifies a min
month of 1 month ago and a max
month of 1 month time. Therefore the user can only select the months that fall within that range.
<form name="myForm2" action="http://www.htmlcodes.ws/resources/html-forms-action.cfm">
<input type="month" min="2024-09" max="2024-11" name="myMonthField2">
<button>Submit</button>
</form>
Specifying a step
You can also use the step
attribute to limit the number of months the user can choose from.
The following example uses a step
value of 2
, resulting in every second month being unavailable.
<form name="myForm3" action="http://www.htmlcodes.ws/resources/html-forms-action.cfm">
<input type="month" step="2" name="myMonthField3">
<button>Submit</button>
</form>
The month
value was not introduced in HTML5, but at the time of writing, it has been introduced in the HTML 5.1 draft, as well as the WHATWG HTML Living Standard.
You can also use the datetime
, datetime-local
, time
, week
, and date
values when working with dates and times.