False. Many zip codes include more than one city, and some even cross multiple states. And you can't always tell the difference between codes from different countries. Now you're not just instantly filling the rest of the form, you're implementing fancy multi-country filtering logic, editable drop downs, etc. Given the obvious incompetence of the people implementing most web forms, you're asking for disaster here.
Instead, learn to use your browser's autofill feature, and design your sites with it in mind. If you do it right the user literally doesn't have to type a single character. That's even better than typing a numeric code. Sadly even this seems beyond the abilities of the people who implement web forms.
This does mean that you might autofill a city name that is "wrong" in the view of the person completing the address form, but much of the bulk mail they receive probably uses that city name anyway.
Technically speaking ZIP codes are not "supposed" to span states but, in exceptional cases, some do. In this case USPS handles it the same way: the state of the preferred city is the preferred state for the ZIP code.
The preferred city is almost always the location of the post office serving the ZIP, which makes this situation fairly intuitive. You can find some interesting edge cases where a post office in located in a suburb city, resulting in a ZIP that includes part of a major city having the suburb as its preferred city name.
You can look up the city name and alternates for a ZIP here: https://tools.usps.com/zip-code-lookup.htm?citybyzipcode and the Domestic Mailing Manual covers this, although it's scattered across several sections and mostly part of how the City State database (the database used for validating city and state names in addresses) works.
What I want to know is: Why isn't this preferred city+state mapping dataset for zip codes publicly available from USPS? It would be like 40kb of data for the entire thing. Why is this not public domain from the US Government?
Edit: or is this what I'm looking for (the "Physical City", "Physical State" columns? https://postalpro.usps.com/ZIP_Locale_Detail
It's missing 00501 at least (which zippopotam has), and military zip codes (which zippopotam doesn't have). Military zip codes are included in this file: https://postalpro.usps.com/areadist_ZIP5
Also fun fact 88888 is for "Operation Santa" uspsoperationsanta.com, which zippopotam is missing, but appears in the areadist_ZIP5 file.
That said, the ZIP DB is indeed not very large, so you can find copies of it. You won't generally find complete copies of the City State file but I wouldn't be surprised if there is one out there.
I've heard this before but it raises a million questions for me and I don't understand how this doesn't cause massive systematic problems and headaches in practice. Are residents even usually well-aware what city they live in, versus what's on their postal address? I sure as heck have always assumed whatever my mailing address says is the city I live in; I can't imagine a ton of people questioning it.
Doesn't this mean a ton of citizens would be registering for the wrong state's elections? Do the election officials always catch these? What about businesses - don't they constantly pay taxes incorrectly if the address is written incorrectly? What about laws (say privacy, wiretapping/call recording, etc.) where people make assumptions based on the city and state - what if they're wrong because the written city isn't the actual city? Who's criminally liable then?? Does every business have to perform a jurisdiction lookup to make sure an address isn't misleading?
Likewise, if you live in another state, there's little confusion because state lines appear on maps and are well marked on all major roads.
Businesses and individuals are responsible for knowing which state they reside in and paying the appropriate taxes, regardless of where their mail is sorted.
As for elections, electoral districts don't generally align with city limits in the first place, so this has to be sorted out by the election registration system based on the full address in most cases anyway.
As for what city name appears in legal documents, the answer is that "preferred" doesn't mean "mandatory". A warrant to search the Indianapolis Motor Speedway, 4790 W 16th St, Speedway IN, 46222, would be perfectly valid, despite the fact that the USPS prefers mail to be addressed to "Indianapolis" rather than "Speedway". For there to be any possibility of confusion, you'd need to have two distinct locations, whose identical addresses share a ZIP code, and differ only by city name, which for obvious reasons the postal service will not allow.
Still, it is rarely a problem in practice, because anyone relying on addresses to establish these legal details will have to look at where the address is actually located---not just the city written in it. Keep in mind that quite a few people live in ZIPs where they could write multiple city names in their address.
When it comes to the unusual case of spanning states, it might help to note that the City State Database the postal service uses to validate addresses does not actually differentiate between city and state. "NEW YORK NY" is a single string. The state is really just part of the city name. The fact that USPS implemented it this way indicates the extent to which it does not matter in operational reality.
A sibling comment points this out, but it might also help to explain that in the US, it is very common for people to have mailing addresses in cities they do not actually live in. That's because of suburbs. City lines are often surprisingly arbitrary and reflect complex political histories. Many people consider themselves to live in [major city] but, in legal actuality, live in [unincorporated county that contains major city]. Many of the upsides of living in the city, sans some of the property taxes and voting in city elections! Yet another reason that people understand that mailing addresses are not definitive reflections of political boundaries.
If you ever work as an election clerk you will find this a LOT---people indignant that they cannot vote for the mayor, to whom you will have to explain, somehow for the first time, that they do not actually live in city limits. This tends to be more obvious if you get a property tax bill but a lot of people are renters and never really think about that aspect.
Do zipcodes change for example? Can your drop-down quickly go out-of-date? You'd need a way to manually enter a city so people are able to tell the system an address. Do you want to bother making an auto-updating zipcode feature just for a form?
Is it going to confuse people because nobody else has bothered to make this superfancy selection feature thing?
Is this USA only? There are postal codes/zipcode-equivalents in other countries.
It starts to feel it's likely not worth the time and effort to try to be smart about this particular feature. At least not if I'm imagining this us some generic, universal address web form that is supposed to be usable for USA-sized areas.
To me it feels similar to that famous article about what you can and cannot assume about people's names; turns out they can be way more complicated and weird than one might assume.
Although maybe zipcodes don't really go that deep in complexity. But on the spot I would not dare to assume they are.
But in TFA's example it does not (my zip has 3 possible city names; TFA's example shows only 1).
These are reasons you cannot deduce the Zip from the city, not the opposite. A ZIP+4 actually encodes all other information for a US address.
Proof: a post office has its own zip code, for PO Boxes.
The +4 is the last four digits of the post office box.
If the Post Office has more than 10,000 boxes, the +4 will be duplicated.
Is that an issue? Who cares that new york city has 20+ zip codes? Just fill autofill "new york city, new york".
>for example, some zip's are just for Post Office Boxes.
Again, is it bad except for some joker who wants something sent to an invalid address?
The fact that "A city can also exist in multiple zip codes. And there can be multiple cities with the same name in the same state" is a good point IN FAVOR of asking for the zip code first (NOT to avoid it) because you certainly can't do it the other way round.
And if you just leave it to the user to free-type all that info in, you have to verify it after... Users are going to make typos, and the USPS will kick your butt if you don't correct it (and credit card payments won't go through, either). So it may be less work for web-form creators, but pushing the verification down stream just makes it all worse for the company using it.
I.e. using something like https://ipinfo.io/json and then typing in a full postcode and street name + number should work well in most cases.
Autofill solves all of that with an implementation cost that approaches zero.
Sure but a zip code belongs to only one city and one state, right?
Funny that the best solution is circa-1997 Netscape 2.0-level technology, while everyone iterates on how we can make everyone's life worse with even more unnecessary JavaScript. Like we all collectively forgot what the <FORM> tag does.
To type an address on a letter, something a 5 year-old could do with a crayon.
Address forms, with unnecessary and unhelpful drop-downs, many of which reject keyboard input and require use of a mouse to scroll through them, are the bane of my existence.
These tools are more than often wrong, and cause more grief for the user than any potential help it could provide.
There is no developer in the world that knows this data better than the person typing it into the form.
that way it's faster and easier for 90% (just a guess) and no different for folks that have multiple cities on that zip
Those few with the luck to live at zip codes that span cities and cross state borders would still still have to fill these in manually, like the 100% of us currently.
It's a pure improvement with no downsides, except the downside of slightly changing the 100-years-old sequence of address fields. Put the ZIP code first, and your customers are going to be happy with that.
I've had them tell me I need 5 digits for my postal code in Norway, which uses 4 digits. I selected Norway in the shipping web form.
Or when they tell me special characters aren't allowed, yet the "special characters" are just letters in the Norwegian alphabet. My address contains ø. These aren't even unicode, they're in the extended 8 bit ascii set. Why are you linting these!?
These happen all the time. Thankfully our postal system recognises this and allows some substitutions (å=aa, ø=oe, æ=ae).
I learned from a cashier to type 00000 and it has always worked.
Would be simple enough to have someone type the zip or postal code first, then move the countries that are known to have that zip code to the top of the drop down (still in alphabetical order), and all the other countries below that (also in alphabetical order).
Leave all the fields editable, i.e. the postal code only suggests, ranks, or prepopulates.
Seems like that would handle all the edge cases, including those where a zip code doesn't refer to one and only one city, or where a zip code has changed or been added to a country.
That gets around countries that consider their postal code database a licensed dataset.
Include a field for the country that is autofilled via Geolocation API or geoip if that's unavailable.
> From those 5 characters you can determine the city, the state, and the country.
You can't infer the country from a postcode.
I did a very brief search, and none of the commercial offerings I could test recognised the postcode of the Eastern European neighbourhood I was born in. Also, like half of African countries don't have postcodes. It's just not a good system.
Even if they fixed that, there are other issues. (You pretty much need to cross-reference it with a database, which assumes said database even exists.)
But the author has a point. Combine it with some approximate country-level geolocate of the web client and this would work perfectly 99% of the time modulo edge cases like VPN users.
I have seen websites that more-or-less takes the author's advice though. They are country specific. They are backed by the postal system's database. They present a list of addresses that match up with the postal code. They do not work very well when a particular address does not have a postal code. And yes, that happens.
That said, the obvious solution is <country> <post code> where <country> is prepopulated from geo-ip or browser signals or similar.
Any company able to do business in multiple jurisdictions, well, that's just the kind of extra thing they can handle.
For an enormous amount of sites and for an enormous amount of users this is an improvement and the general reaction here is nitpicking and this self-evident charge that it's US-centric. So what. The principle would apply in most places.
In Costa Rica, there are no addresses but there are (now) post codes. You would have to take that into account to do business there. If this doesn't apply to you then it doesn't apply to you.
It's not like the internal US market is small. This solves a problem for a lot of people in a lot of cases.
The page itself specifically says "and country", however that too doesn't work. Other non us countries may have the same postal codes, or in my case mine is 4 digits, and I had to figure out that "oh, this is us only and it doesn't work at all for me", which was just entirely a waste of time.
When I look for a part for my car, I pick “Honda”, “Model Year”, “model”, “trim”.
With address forms, if I type “U” in a keyboard aware field, it defaults to “US Minor Outlying Islands”. Places that try to accommodate will put the US and Canada first.
If you asked country, first, you could utilize the postcode method. Some sites try to autocomplete street address which I personally find annoying as my street is a common streetname.
United Kingdom
Great Britain
Britain
England
The filtering value is big as you said, and the model year as a first filter is easy to type in, and probably gets you reasonably close if you're off-by-one. Accidentally picking an '05 Sonata instead of an '04 probably has similar parts, but if you pick Honda instead of Hyundai, you're way off in Wonderland.
E.g. trying to enter a Canadian postal code in a US zip code field fucks a lot of things up. Very frustrating for Canadians trying to buy gas in Washington when the pump asks for a zip.
Proposing UX improvements is great, but please don't forget the other 95% of the planet.
This person bought a whole domain for something that doesn’t work for 90% of the world, claiming it does, never even testing their assumption. Great job!
How long have we had browser auto complete for addresses? A long time, I assume it's devs like this one who just can't be bothered to support it and have to pretend their flawed approach is somehow faster than literal auto complete.
It’s addressed in the article (at the end, admittedly).
I don't disagree with reordering the entry by relevance, but you have to start with country. That can also be a nice search - it will be a very short lookup, even if you put every country name in every language. Only after that is postal code (of whatever kind - it's only ZIP in the US) relevant.
It works great, except my address is for some reason not in whatever databases these websites use. The building number is on the list, but not the individual flats. So I have to put in the postcode, choose something like "My address is not listed", then fill in the form manually. A few times it wasn't even offered as an option.
[0] https://en.wikipedia.org/wiki/Postcode_Address_File [1] https://www.royalmail.com/personal/receiving-mail/update-you...
For instance, my postcode covers 15 houses and half of a large park. Those houses have been subdivided into 4-6 flats, and many have been redivided or renumbered multiple times. The park also contains various buildings and other places that might plausibly receive deliveries, some of which have multiple entries (an electricity substation appears 8 times, for some reason). So in total, it covers more than 200 addresses - mine is no.140-ish in a typical sorted list.
You'd be amazed by how many address checkers can't handle more than 64, 100, or 128 addresses in a postcode. Or how many scrollbars stop working, requiring you to use the arrow keys to navigate. Or how many other glitches I've seen.
The other common problems are usually down to temporary postcodes (which used to always end with an 'X' but can now be indistinguishable from 'real' codes) escaping into the wild, re-addressings and re-numberings not being picked up properly, the old problem of outdated PAFs being used, and - my personal favourite - BT/Openreach using their own separate postcode database, dating from the Post Office split in the early 1980s, which doesn't always agree with the PAF. Agh!
The PAF is about what the Royal Mail calls "Delivery Points" which are places they promise to deliver physical letters to. Inside my building for example every home has a front door, with a letter box, and letters literally get posted into my flat, but down the street there's a building with a rack of boxes set into the wall and post is delivered to your numbered box, and up the street there's a townhouse converted and all the mail just goes in one piles for everybody in that building.
Many delivery points share a postcode, but because they know them all they actually all have unique numbers, and unlike a postcode they're not for humans so they get changed quite frequently as new buildings are constructed or working patterns change, if you examine your post carefully (in the UK†) there are two rows of fluorescent orange dots on the outside, these were printed by mail sorting machines shortly after the mail was received, one is an entirely arbitrary serial number and it designates that piece of mail for a very short period (say a few days) to enable statistical tracking for performance - if #213940202 entered the system in Glasgow on Monday, was in Portsmouth by Tuesday but wasn't delivered to someone's door until Friday the problem ain't in Glasgow. But the other one we're interested in here is the Delivery Point as a numeric code. If you don't have multiple addresses this row of orange dots will be identical on every item you've received for some time yet it's different on someone else's mail.
† This trick was invented in Britain but is used (licensed) in some other countries because it's a good idea, however exactly what is encoded and so what it "means" may vary.
“I type 90210. You now know I'm in Beverly Hills, California, United States. You didn't need me to tell you that. You didn't need a dropdown. You didn't need me to scroll past Turkmenistan.”
The point stands that this doesn't "just work" for global services.
I think auto full suggestion should be just that -- a suggestion, not validation.
I eventually had to dig through a bunch of USPS documentation for their Address Element Correction database to find their helpdesk. Apparently places like Fedex use that database.
So I agree as well, and I would be pretty angry if someone forced me to pick from a list instead of just trusting that I know my own address.
Also as another aside I was a shipping clerk for a while and occasionally came across an address like “across from such-and such store halfway down the alley.” So the author is making a pretty bold assumption that there is such a thing as a standard address that can be auto-filled.
What happens to customers not in the United States? They have no zip to enter. Or if they have a postal code of some stripe, it has a different format.
What about folks who are in Turkmenistan, that you’re grumpy about having to scroll past? How are they signing up?
Zipcode is easy, the platform likely wants my postal code.
You have to be a little bit more creative with state, sometimes "We don't have any states" is fun to see printed on your address label on a parcel, other times "Denmark" could be considered a state in the EU and that can be an answer, but most times "N/A" is enough.
And even if you knew that, the only thing you could have known from the zip code is the city. At least roughly, because multiple small villages share one zip code.
Or, to cut it short: This doesn’t work at all on a general and global level, so I guess there’s a reason why websites do this differently…
From outside the US: I always thought "zip code" is just what you USers call a postal code. I only found out it's a trademark today, from this HN discussion.
So most people outside the US will see "zip code" and think "oh, they mean postal code but they have this weird term for it".
ZIP is an acronym for "Zone Improvement Plan", but no one knows that and it's not meaningful if you do!
* correcting myself, some zip codes do cross state lines
https://dataprivacylab.org/projects/identifiability/index.ht...
I would have assumed that you knew that. I know people whose ZIP code belongs to a neighboring town (because mail works that way) and it basically becomes their de-facto address.
But if you get mail to an address with a ZIP code listed to another city then surely you're aware of this as it comes up constantly for anyone who ever receives mail or packages.
I used to live in M6C1B5. By forcing "numeric" on the zip code field, you'd immediately loose all Canadians.
This article is so US centric it's not even funny.
Ofc there are edge cases. So since there exist a handful of edge cases where a zip code maps to two states, or the more frequent (but irrelevant in the US) case of two or more city names per zip code, we should make everyone suffer?
Ofc if you are making a web form you should ask for the zip code first, and auto complete state and city. Let the user edit them if they don’t like what you chose. Or do as some have suggested here and present the official USPS data as a drop down of 2 states or 2-3 cities; thats way better than having to type all of it.
And I curse everyone who thinks it’s a good idea to break zip code or phone number or OTP into multiple fields, or if you’re too lazy to set the input type to number.
p.s.: Don't takt this too serious, have just a dark kind of humor.
There are zip codes that map to more than one city.
There are zip codes that map to more than one state. (42223)
Line houses are even more interesting: https://en.wikipedia.org/wiki/Line_house
> A US ZIP code is 5 characters. From those 5 characters you can determine the city, the state, and the country. That's 3 fields. Autofilled. From one input.
I guess this is par for the course in Trump's America, but I still feel embarrassed for the creator.
This works within a country, but not between countries.
For example 77520 is the zip code of Cancun, Mexico and Baytown, Texas.
---
Needs to be country + zip code (postal code).
You CAN’T get the country from a zip code. France also use 5 digits zip code for example. You must ask for the country before asking for the zip code, even if you pre fill it with a sane default, like the main country you operate in.
Also, don't be a dick. Have some empathy for your reader. Half of the UI designers you are talking to don't have a choice in how it works. Their colleagues chose some stupid framework which they can't customize. The other half didn't even want to do this task, they just got it assigned to them by some PM they don't respect (who, in turn, does not respect any advice coming from UI designers), and they are doing the minimum they possibly can while applying to other jobs that suck less.
08036 Barcelona, Barcelona, Spain
08036 Hainesport, New Jersey, USA
It does make some sense to go from most general (country) to more specific (address) instead of the opposite, so the form can implement better auto completions.
However in practice postal addresses are not that clean so simple dumb forms are usually better, because it's easy for exceptions to be missed by auto completion algorithms. I would be very pissed if I had to type the zip code above and then correct the wrong guess on every website.
Either you are helpful and guess correctly or you don't guess at all.
This guy just keeps digging himself into a hole of ignorance - is he aware of Mexico? Canada?
const msgs = [
`Yes, we know ${country} exists. We're very proud of you.<br><br>This site is about US address forms — the ones that make <em>Americans</em> scroll past Turkmenistan 200 times a year. You have your own postal code problems. We believe in you.`,
`We see you're visiting from ${country}. Welcome. We regret to inform you that this rant is specifically about American address forms, which are — and we cannot stress this enough — <em>unbelievably bad</em>.<br><br>Your country probably has its own postal code horrors. We'd love to hear about them: <a href='mailto:shame@zipcodefirst.com'>shame@zipcodefirst.com</a>`,
`Hello from across the pond (or whichever body of water separates us from ${country}). This is a US ZIP code website. We are aware that other countries exist. We just have 160 million addresses and a 50-state dropdown to be mad about first.<br><br>Your frustrations are valid. Your postal codes are also useful. Put them first too.`
];Even in forms where I've designed this it breaks my flow as a user. I'm used to suburb state postcode order (I'm an Aussie). It's how we were taught to write the address in school. It's been a pattern for a long time, and the reversal of the fields slows my brain down.
IMHO The better user experience isn't changing the order of the fields. It's honouring auto-complete so the user doesn't have to enter this data in the first place.
But just for reference, in Singapore, we use 6-digit zip codes, each of which can uniquely locate a single building, so yes, a lot of local websites essentially just expect a zip code plus unit number, without the hassle of typing out the address at all.
Maybe what I wanted to say is, the idea is cool and _can_ work to enhance user experience with proper localization.
I'm not in the UK and even I know their postal codes have letters in them, cmon mate...
Three or four blank lines is probably the least hostile and most foolproof way to handle addresses.
But the cart software has distinct address-line-1, address-line-2, city, state, zip-code fields.
And the CRM they export into has similar fields.
Probably to be compatible with some further pipeline of tooling going back decades.
I suspect if you go back far enough it ends at pre-/semi-computerized data processing systems which would print addressed envelopes and documents from stacks of Hollerith cards, using extremely rigid fixed formats that were probably fine for their original buyers, likely US-centric and old enough that they were just getting it to the right city and letting the local postman figure out the nonsense on the envelope.
despite the obvious flaws others have already noted, plenty of countries include letters in their zipcodes, rendering the "Invoke the right keyboard" argument not only incorrect but potentially damaging to users or businesses who choose to follow this. if the website won't allow me to physically enter my zipcode, i'll just take my business elsewhere.
For the US you can use zip-5 to prefill bunch of data and zip+4 practically fills it all out for a lot of addresses.
Each country has some particular nuance though, so it's only as simple as "zip first" or "postcode first" in some locations.
https://github.com/BrianHenryIE/bh-wc-postcode-address-autof...
That would have all the desired properties and then some, and would work everywhere on Earth.
All zip codes are postal codes, but not all postal codes are zip codes.
At my last gig, this sentence was said a lot, and people kept confusing the two, both in code and in daily speech, so maybe colloquially they are the same :)
It is possible to do this properly, e. G., DHL and UPS do a somewhat okay job of it but isn't easy.
See: https://peter-horton.com/2022/12/30/zip-codes-zctas-and-zcta...
This is not new. Some checkouts do start with zip code and they feel much more efficient. (US only delivery, so country already assumed)
If you started with just the zip you still have to type your street address afterwards.
Just kidding xP
JRandomCustomer enters street-number, apt-number, city, state, code ... in that order.
Also, many websites seem to have a negotiation with the browser, where, given: a street address, -> they can populate the other fields.
Definitely not perfect
On a personal note, please just let my browser autofill my address.
The devs know how to make the experience better, but they get paid to implement some mbas mining scheme.
The future is ok but mostly sucks.
The zip first suggestion seems that would be really inconvenient for around 95.8% of the world population.
the "fields", like the goggles, they do nothing
I've encountered websites that take the zip and won't let me change the wrongly-assumed city
PD: if you don't get the reference, a classic: https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-...
Also: the awesome-falsehood collection: https://github.com/kdeldycke/awesome-falsehood
> Fine, maybe country first
It's an example - limit typing. But adjust it to your own use case.
I tried the example with my local post code and of course it didn’t work as I’m not in the US.
- Put the country first
- Put the zip code second
Like the author I cannot stand how stupid some checkout processes are!
You’d absolutely have to determine that you’re in the US before asking for zip code.
“This is is a terrible idea, you’re telling me you will make 99% of cases way faster but completely ignore the 1% that will be slightly slower? Unbelievable.”
If you have SA that most of your customers are in USA, this is a good idea. If not, maybe use your brain a bit and figure out if it can be adapted to something which will work for your customer base.
The trick, then, is that you don't remove anything from the alphabetical list. With modern computer technology, we can have two places to find something! So if I miss your fancy shortcut, or it's not applicable to me, everything will still be in the regular old familiar place. It just works.
Absolutely not. Language should never have any merit at all on country selection.
As a Swede that prefers the English language for tech and internet stuff, sites that try to be smart about country selection based on browser language or language selection based on IP location can kindly go die in a fire. An extra hot fire if they don't even let you manually override the automatic "detection".
It's not evil like forced language/region selection with no fix available.
Does this work for zips? Some zips have a leading 0.
All that said, free-form entry is a hard sell. My _customers_ expect field data entry, so I implement field data entry. I just re-order my checks to be more forgiving until the data entry is complete.
I was implementing a customer service address entry using significance order 25 years ago. As I already _knew_ that I had a US-centric customer base (we sold long distance to sorority and fraternity members), entering US ZIP first saved a lot of time and more highly leveraged the US postal address cleaner that we had already purchased for our mass marketing mailers. The people working the call center _loved_ it, as they could focus more on their call turn-over than on data entry.
Anyways, further reading:
https://aldavigdis.dev/2023/03/25/falsehoods-programmers-bel...
https://github.com/kdeldycke/awesome-falsehood?tab=readme-ov...
Zip codes map to postal routes, not polygons
Nope! Didn't see that. Seems the zip code registry doesn't have a number of German zip codes.
Zip codes repeat across countries, you know.
The fact that mail gets to its destination when it does, as soon as it does, with overall minimal error, is nothing short of amazing.
But some web dev blogger has it All. Figured. Out.
Right.
I'm sure your way is better.
This is big "I could code it in a weekend" HN energy.
The USPS owes you a debt of gratitude for buying a snarky domain and bringing this to their attention after 63 years.