Course contentsShow
← Web Development
Lesson 95 of 2,9822. HTML FundamentalsFree lesson

Date and Time Input Types

Using date, time, datetime-local, month, and week inputs for temporal data collection.

Date and Time Input Types

You'll learn how HTML provides specialized input fields for collecting dates, times, and related temporal data from users.

Understanding Temporal Inputs

When you need users to pick a date for an appointment, select their birthday, or choose a time slot, HTML offers dedicated input types that create calendar pickers and time selectors automatically. These work much like how your phone's calendar app provides a visual interface instead of forcing you to type "03/15/2024" manually.

The Five Temporal Input Types

<input type="date"> – Lets users select a specific day, month, and year. The browser shows a date picker interface.

<input type="time"> – For selecting hours and minutes (and optionally seconds). Great for appointment times.

<input type="datetime-local" – Combines both date and time selection in one field. Perfect for scheduling events with specific start times.

<input type="month"> – Selects just a month and year. Useful for credit card expiration dates or "When did you graduate?" questions.

<input type="week"> – Lets users pick a specific week of the year. Less common, but helpful for weekly planning scenarios.

Why Use These Instead of Text?

Browsers provide built-in validation (ensuring February 30th can't be selected), consistent formatting across devices, and mobile-friendly picker interfaces. Users can't accidentally type "13/45/2024" when the browser handles the input mechanism.

Basic Syntax Example

<label for="appointment">Choose appointment date:</label>
<input type="date" id="appointment" name="appointment">

<label for="meeting-time">Select time:</label>
<input type="time" id="meeting-time" name="meeting-time">

Key Takeaway: HTML's temporal input types (date, time, datetime-local, month, week) provide user-friendly, validated interfaces for collecting time-based data without requiring custom JavaScript calendars.