In this article, you will learn how to accept date, time, both date & time, month and week from the user in HTML.
In HTML, there are various formats to accept Date and Time from the user. For example, we can input time only, date only, both date & time and so on.
Input Date and Time in HTML 📆
It allows us to select both date and time.
- Set the type attribute of input element to datetime-local.
- Use min and max attributes, to allow user to select the date and time within a given date range.
Input Date in HTML 📅
It allows us to select date only.
- Set the type attribute of input element to date.
- In some browsers, it will either render a textbox that validates the date or a special date picker interface.
- To select the date within a given range by using min and max attributes.
Input Time in HTML ⏲
It allows us to select time only.
- Set the type attribute of input element to time.
- Use min and max attributes to select the time within a given time period.
Input Month in HTML
It allows us to select month only.
- Set the type attribute of input element to month.
- Use min and max attributes to restrict the month range along with years.
Input Week in HTML
It allows us to select week only.
- Set the type attribute of input element to week.
- Use min and max attributes to select the week number range along with years.
Learn more about various input types in HTML by clicking here.
Comments