mobile development
date picker
web app
iOS
Android

Invoke native date picker from web-app on iOS/Android

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The most reliable way to open a native date picker from a mobile web app is to use a real HTML date input. On current iOS and Android browsers, input type="date" lets the browser hand off to the operating system, which gives users the familiar picker they already know.

Use input type="date" First

A web app cannot directly call private iOS or Android picker APIs. The browser is the only bridge, so the correct starting point is a standard form control rather than a custom calendar widget.

In practice, that means rendering a visible date field and letting the browser choose the native UI. This keeps localization, accessibility, and keyboard behavior aligned with the device.

html
1<!doctype html>
2<html lang="en">
3  <head>
4    <meta charset="utf-8" />
5    <meta name="viewport" content="width=device-width, initial-scale=1" />
6    <title>Native date picker</title>
7  </head>
8  <body>
9    <label for="tripDate">Trip date</label>
10    <input id="tripDate" type="date" min="2026-01-01" max="2026-12-31" />
11  </body>
12</html>

On Android Chrome this usually opens a calendar dialog. On iPhone Safari it opens the platform date control when the user taps into the field. The visual style is different across devices, but that is expected because the goal is native behavior, not identical pixels.

Opening the Picker From a Button

Sometimes the design uses a custom button instead of asking the user to tap the field. The cleanest approach is to keep the input visible and call showPicker() when the browser supports it. If not, fall back to focusing and clicking the input during the same user gesture.

html
1<form id="bookingForm">
2  <label for="bookingDate">Booking date</label>
3  <input id="bookingDate" type="date" />
4  <button id="chooseDate" type="button">Choose date</button>
5  <button type="submit">Save</button>
6</form>
7
8<script>
9  const dateInput = document.getElementById("bookingDate");
10  const chooseButton = document.getElementById("chooseDate");
11
12  chooseButton.addEventListener("click", () => {
13    if (typeof dateInput.showPicker === "function") {
14      dateInput.showPicker();
15      return;
16    }
17
18    dateInput.focus();
19    dateInput.click();
20  });
21</script>

This must run from a real tap or click. Browsers usually block picker-opening code that runs automatically on page load or from delayed timers.

Working With the Selected Value

The browser returns a value like 2026-03-07. That string represents a calendar date, not a timezone-aware timestamp. Keep that distinction clear when sending the value to an API.

javascript
1const form = document.getElementById("bookingForm");
2const dateInput = document.getElementById("bookingDate");
3
4form.addEventListener("submit", async event => {
5  event.preventDefault();
6
7  if (!dateInput.value) {
8    alert("Select a date first.");
9    return;
10  }
11
12  const response = await fetch("/api/bookings", {
13    method: "POST",
14    headers: {
15      "Content-Type": "application/json"
16    },
17    body: JSON.stringify({
18      bookingDate: dateInput.value
19    })
20  });
21
22  if (!response.ok) {
23    alert("Request failed.");
24  }
25});

If your backend stores date-only business values such as birthdays, due dates, or reservation days, keep them as plain dates. Only convert to a full timestamp when you truly mean an instant in time.

When a Custom Picker Makes Sense

Native pickers are usually the best mobile answer, but there are exceptions. A travel search flow may need side-by-side months, blackout ranges, or pricing shown on each day. In cases like that, a custom calendar can be justified.

Even then, many teams still use the native input on smaller screens because it is faster, more accessible, and less fragile than a hand-built picker.

Common Pitfalls

The most common mistake is hiding the date input with display: none and trying to trigger it from a decorative element. Some browsers will refuse to open the picker if the real control is not interactable.

Another issue is marking the input readonly. On mobile browsers that often prevents the native picker from opening at all.

Timezone confusion is also common. A chosen date like 2026-03-07 should not automatically become midnight UTC unless that conversion is intentional.

Summary

  • Use input type="date" as the default way to invoke the native picker in a mobile web app.
  • Keep a real input in the layout instead of fully hiding it.
  • Use showPicker() when available, then fall back to focus() and click() during a user gesture.
  • Treat the selected value as a date string unless your backend needs a true timestamp.
  • Reach for a custom calendar only when native controls cannot support the required UX.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.