Autofill a city and region from a postal code

Speed up checkout and sign-up forms — when a user types their ZIP or postal code, fill in the city and region automatically with one free API call. No key.

Back

A faster address form: the moment someone types their postal code, fill the city and region for them. It's one request, no key, and it cuts a few fields off every checkout.

The lookup

curl https://countries.dev/postal/US/10001
[{ "placeName": "New York", "admin1": { "name": "New York" }, "latitude": 40.7484, "longitude": -73.9967 }]

Wire it to the form

When the postal-code field changes, look it up and fill the rest:

zipInput.addEventListener('change', async () => {
  const [place] = await fetch(
    `https://countries.dev/postal/${country}/${encodeURIComponent(zipInput.value)}`,
  ).then((r) => r.json());

  if (place) {
    cityField.value = place.placeName;
    regionField.value = place.admin1?.name ?? '';
  }
});

Because it returns coordinates too, you can also drop a map pin or compute a shipping distance from the same response.

Pair it with a country picker

Let users choose the country first — a country dropdown gives you the ISO code to pass straight into the postal lookup. The full postal code API covers 121 countries, keyless. See the docs for the response shape.

Written by

Dov Azencot

At

Fri Jun 26 2026