HTML Date

HTML5 introduced a new input type called "date" that allows users to select a date from a calendar widget. This input type can be useful for forms that require users to enter a date, such as a birthday or appointment date.

To use the "date" input type, you can add the following code to your HTML form:

<label for="birthday">Birthday:</label>
    <input type="date" id="birthday" name="birthday">

In this example, the "type" attribute of the input element is set to "date", and the "id" and "name" attributes are set to "birthday". The "for" attribute of the label element is also set to "birthday", which links the label to the input element.

When a user selects a date using the calendar widget, the date is stored in the format "YYYY-MM-DD", which can be easily parsed by JavaScript or other programming languages.

Note that not all browsers support the "date" input type, so it's a good practice to provide a fallback option, such as a text input field or a custom date picker widget, for users whose browsers do not support this input type.

Next Article ❯