How to Make the Year Fixed in "month" input HTML Element?

Making the year fixed/non-editable in HTML "month" input element

When using the HTML <input type="month"> element, you can make it so that only the month is allowed to be editable, and the year is fixed/non-editable. You can do so by setting the same value for the year in the min and max attributes.

For example, to keep the year fixed as "2022", and only allow the month to be editable, you can do the following:

<input type="month" min="2022-01" max="2022-12" />

Before you use the <input type="month"> element, please make sure that you're aware of the browser support.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.