HTML Date Picker

Date Picker in HTML Forms: Selecting Dates Made Simple

Imagine trying to type a birthdate or appointment by hand — frustrating, error-prone, and clunky. Thankfully, HTML provides a smooth solution: the <input type="date">. This control opens a browser-native calendar, allowing users to select a valid date effortlessly.

Basic Syntax of the Date Picker

To create a date picker, simply use the type="date" input type.

<label for="birthday">Select your birthday:</label><br>
<input type="date" id="birthday" name="birthday">
Select your birthday: [ 📅  Select Date ]

When the user clicks the input field, a calendar UI pops up (in supporting browsers), allowing intuitive selection.

Setting Default Dates

Use the value attribute to pre-fill the input with a specific date.

<input type="date" name="fruitDate" value="2025-05-24">
[ 2025-05-24 ]

The value must follow the format YYYY-MM-DD. This standard ensures consistency across all browsers and locales.

Controlling Date Range with min and max

You can define the earliest and latest selectable dates using min and max attributes.

<input type="date" name="deliveryDate" min="2025-06-01" max="2025-06-30">
[ Select a date between June 1–30, 2025 ]

This is ideal for scheduling deliveries, appointments, or registrations within a fixed timeframe.

Combining Required Field Validation

<input type="date" name="startDate" required>

If left empty, the form won’t submit until the user picks a valid date. The browser will prompt the user with a native validation message.

Browser Support Notes

  • Modern browsers like Chrome, Edge, Safari, and Opera support type="date" with a UI calendar.
  • Firefox supports the field but shows a plain text input without a UI (users must type manually unless styled with JS).
  • Older browsers may treat it like a text input — always validate on the backend too.

Full Example: Fruit Delivery Form with Date Picker

<form action="/submit-delivery" method="post">

  <label for="fruit">Choose a fruit:</label><br>
  <select id="fruit" name="fruit" required>
    <option value="" disabled selected>-- Select -->
    <option value="apple">Apple</option>
    <option value="banana">Banana</option>
    <option value="cherry">Cherry</option>
  </select><br><br>

  <label for="deliveryDate">Preferred Delivery Date:</label><br>
  <input type="date" id="deliveryDate" name="deliveryDate"
          min="2025-06-01" max="2025-06-30" required><br><br>

  <input type="submit" value="Schedule Delivery">

</form>
Choose a fruit: [ Apple ▼ ]
Preferred Delivery Date: [ 📅  Select Date ]
[Schedule Delivery]

Best Practices

  • Always use YYYY-MM-DD format for default values
  • Set realistic min and max dates to prevent invalid selections
  • Combine with required for important fields
  • Handle unsupported browsers with fallback messaging or server-side checks

Summary

The type="date" input makes selecting valid dates easier, faster, and less error-prone. You’ve learned how to:

  • Create a date picker with HTML
  • Pre-fill, limit, and validate date entries
  • Ensure cross-browser usability

Check your understanding 1

Which HTML input type should be used to allow users to select a date from a calendar UI?
Choose one answer. You can try again.

Answer and explanation

<code>type="date"</code>

Use type="date" to present a native date picker in browsers. Ideal for fields like ‘Date of Birth’ or ‘Exam Date’.

Check your understanding 2

Using type="date" automatically ensures that the entered date format is consistent across all browsers.
Choose one answer. You can try again.

Answer and explanation

False

The actual display format may vary slightly across browsers (e.g., MM/DD/YYYY in US locales vs DD/MM/YYYY in India), but the internal value is always submitted as YYYY-MM-DD.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. Provides a calendar pop-up in supported browsers
  2. Can be restricted using min and max
  3. Allows multiple date selections at once
  4. Returns date values in YYYY-MM-DD format
Which of the following are correct features or uses of the HTML input type="date"?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2 and 4

The date input provides a single calendar selection, can be bounded by min/max, and returns a standard format value. Multiple dates require JS or third-party libraries.

Check your understanding 4

Which value will be submitted by the following field if the user selects 15 August 2024? <input type="date" name="independence_day">
Choose one answer. You can try again.

Answer and explanation

2024-08-15

Regardless of how the date appears to the user, the submitted value is always in YYYY-MM-DD format: 2024-08-15.

Check your understanding 5

All browsers support input type="date" with a built-in calendar picker.
Choose one answer. You can try again.

Answer and explanation

False

Modern browsers like Chrome, Edge, and Safari support it. But some older versions or non-visual browsers may not render the calendar and fall back to a plain text field.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. <input type="date" min="2024-01-01" max="2024-12-31">
  2. <input type="date" pattern="\d{4}-\d{2}-\d{2}">
  3. <input type="date" step="1">
  4. <input type="date" range="true">
Which of the following are valid ways to limit user input to a specific date range?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3

You can restrict date input using min and max. Though pattern is allowed, it’s redundant and ignored on type="date". range is not a valid attribute.

What’s Next?

Next up: Learn how to use the range slider input to collect numeric values with a visual, interactive control.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML Range Slider →