DEV Community

Cover image for Get Instant Country Flags

Get Instant Country Flags

⚡ Nirazan Basnet ⚡ on April 09, 2021

While working on one of my projects, there is one feature where I need to display a specific flag depending upon the country code. My first approa...
Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited
const getFlagEmoji = countryCode=>String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt()))

getFlagEmoji('GB') // 🇬🇧
getFlagEmoji('JP') // 🇯🇵
getFlagEmoji('ZA') // 🇿🇦
Enter fullscreen mode Exit fullscreen mode
Collapse
 
arunmurugan78 profile image
Arun Murugan

This is Awesome!

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Thanks!!

Collapse
 
simaodeveloper profile image
Daniel Simão

🤣🤣🤣🤣🤣🤣

Collapse
 
kaspermroz profile image
Kasper Mróz

Love it! 🔥

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Thanks!!

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Great.

Collapse
 
davidkrmela profile image
David Krmela

Hi Nirazan, you mentioned Flagpedia.net as a place where you can download the archive with flags. But it also supports API access:

Examples:

There are a lot of different resolution. Maybe someone will find it useful.

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Thanks for the information :)

Collapse
 
jeremypersing profile image
Jeremy Persing

Hey, I was working on a project recently and used your post to implement flags into the project. Unfortunately, half way through the project countryflags.io went down. Because of this, I decided to make my own API, countryflagsapi.com. The API allows you to get a country by it's two letter code (ISO Alpha-2 code), along with the country's name, it's three letter code (ISO Alpha-3 code), or UN code. Thanks for the post Nirazan, and hopefully this API can help anyone that's run into trouble with countryflags.io being down.

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Thanks for the information. Definitely, I will try your api structure.

Collapse
 
banky profile image
Bankole

Nov 11th 2021 - 4:00 a.m. WAT - countryflags.io is down

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Yes, so I had add alternative solution. Hope you like it :)

Collapse
 
tuliocalil profile image
Tulio Calil

🇧🇷

Collapse
 
hgpit profile image
hgpit

Did something happen to this domain? it's been down for at least 2 days now :(

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Yes, the site is down so I had added alternative solution. Hope you like it :)

Collapse
 
mohitm15 profile image
Mohit Maroliya

I guess countryflags.io is not working now.

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Yes, the site is down so I had added alternative solution. Hope you like it :)

Collapse
 
amedalen profile image
Aj

Really inspiring thank you so much, I got really inspired and decided to create a country's capital finder just displaying the capital of any country in python and run on Flask maybe this would help you find any capital you want :)

(dev.to/amedalen/any-countrys-capit...)

Once again thank you for this wonderful post.

Collapse
 
shriji profile image
Shriji

Very neat! I made the svelte version of this!

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Great 🙂🙂

Collapse
 
jorik profile image
Jorik

Great written article! Inspired by your piece, I wrote a small function to achieve this using emoji's! dev.to/jorik/country-code-to-flag-...

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Thanks 😌