How to Make the Year Fixed in "month" input HTML 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.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.